Python Programming

Resources:

Software from python.org

Notes:

  • To create a new script in IDLE: use FILE / NEW.
  • To run a script or program in IDLE, use RUN / RUN MODULE (or F5).
  • Using line numbers: Line Numbers are not displayed on the left-hand side. However, you can go to a specific line with Edit / Go to Line. Also, note that there is a line/column indicator in the lower right corner of the
    IDLE window.

Notes on using Python’s IDLE in Windows:

In order to set a default directory for your programs so that Python does not save them with the rest of Python, you can reconfigure the shortcut on your desktop to specify your own working directory. To do that, right-click on the shortcut on your desktop and choose Properties. In the “Start In:” line, enter your own folder, for example C:PythonClass and then click OK.

Notes on De-bugging in Python’s IDLE:

  • In the SHELL, click on DEBUG / DEBUGGER
  • Select your options (e.g. LOCALS / STACK )
  • Use STEP to go through the program one line at a time and follow how the program executes
  • Use GO to run the program to finish the way that it normally would run (in other words, to stop the STEP behavior).

Additional Python Resources and notes:

Safari Online at the Bobst

Online Resources:

String methods - http://docs.python.org/release/3.0.1/library/stdtypes.html?highlight=capitalize#id4

Mutable Sequence Types (e.g. lists) - http://docs.python.org/release/3.0.1/library/stdtypes.html?highlight=capitalize#mutable-sequence-types

Mapping types (e.g. dictionary) - http://docs.python.org/release/3.0.1/library/stdtypes.html?highlight=capitalize#mapping-types-dict

File objects (File IO) - http://docs.python.org/release/3.0.1/library/stdtypes.html?highlight=capitalize#file-objects

Working with urllib.request for obtaining data from webpages -http://docs.python.org/3.0/library/urllib.request.html  and http://docs.python.org/3.1/howto/urllib2.html

Working with CSV files – reading and writing - http://docs.python.org/3.1/library/csv.html

Some of the differences Between Python 2.x and Python 3.x

Some of the differences to keep in mind with respect to the CSCI-UA.2 syllabus material; there are many more:

Topic Python 2.x Python 3.x
Print statement print ‘Hello, World!’ print(‘Hello, World’)
Data entry: text name = raw_input(‘What is your name? ‘) name = input(‘What is your name? ‘)
Data entry: numbers (values) age = input(‘What is your age? ‘) age = input(‘What is your age? ‘)
age = int(age)
Integer arithmetic: division
>>> 7/2
3

[ where 7 and 2 are integers]

>>> 7/2
3.5
>>> 7//2
3