How To Start Python on Bucknell's Linux Computers

Notes originally by Professor Hyde
  1. Log on to one of the Linux machines in room 164 Breakiron or 213 Dana.

  2. To open a “Terminal” window, select Applications ->Accessories->Terminal from top menu, or with right mouse button in background, select Open in Terminal.

  3. To logoff of Linux machine, select from top menu System->Log Out account_name.

  4. To run the Python interpreter by itself in interactive mode, type in a terminal window at the prompt:
    python

    Type one line of Python at the >>> interactive prompt to try out a snippet of code.

    Type quit() or Control-d to quit python.


  5. To use Python's simple integrated development environment, type in a terminal window at the prompt:
    idle3
    
    which opens a new window with interactive prompt >>>. Try
    >>> 6*7
    

    To enter a Python program within Idle, select File->New Window to open an editor window. Then type:

    # Simple Python program
    def big_number(n):
     return 2**n
    x = int(input('Enter integer value: '))
    y = big_number(x)
    print('2 to the power of', x, 'is', y)
    

    Save your file with .py extension.

    To run your program, select Run->Run Module in the editor window. Try 100 for input.

  6. Use dir(module_name) to see a listing of all the functions in a module. Try the following at the Idle interactive prompt. In using the dir or help function, you can always type the letter 'q' to stop the displaying more information.
    import random # import the module random
    dir(random)
    
  7. Use help(module_name) to see the manual page on a module. Try
    help(random)
    
  8. Use code>help(module_name.function_name) to see short description of the function. Try
    help(random.choice)
    
  9. You may use dir() and help() on a variable that has been assigned a value. Try
    s2 = 'Bison'
    dir(s2)
    help(s2.lower)