Python Crash Course
Python Crash Course is a Practical Python Programming Programme for Pragmatic People
Last Offering
- 2010: January, February.
Lecture 1 [download slides (pdf)]: A Mad Mad Intro – Using Python in Interactive Mode
- Downloading, Installing, Running Python (Windows, Mac, Linux)
- Windows Users: See this tutorial to set DOS path environment variable (external link) — makes Python by typing “python” in console
- Python as a console calculator
- The print statement
- Variables
- A little on Exceptions and a Preview of Functions and Conditionals
Lecture 2 [download slides (pdf) | download all scripts.py (tgz)]: Finishing a Mad Mad Intro
- Introduces features beginners and pros alike should know (conditionals, loops, functions, lists, tuples)
- Scripts that are discussed and modules that they need (put them all in the same folder)
- Scripts for the sneak preview (GUI example, put them in the same folder as pccMathModule.py above)
- mainx.py, pccGuiModule.py
- Instructions:
- Run mainx.py
- Fill in any Four fields out of Five fields with numbers
- Hit the button!
- Full GUI / Object Orientation explanation in Lecture 4.
Lecture 3 [download slides (pdf) | download related files (tgz | zip) | solution script (py)]: Intro to Handling Files and Humans
- Dictionaries and Exceptions
- Beginning file handling (open())
- About the files in the archive (note: the csvmain.py puzzle was solved in class because of its difficulty):
- Instructions for argvmain.py:
- Run argvmain.py using “python argvmain.py“
- Now try running it with a few arguments, e.g. “python argvmain.py The cow eats grass!“
- Look at the script and notice that the sys.argv variable is a list that contains the arguments!
- Instructions for csvmain.py:
- Run it using “python csvmain.py igem_strain_list.csv” to see what happens–
- it should create make a file “output.txt” filled with question marks!
- Note: more instructions are in the comment at the start of the file
- There are several blanks in the file labelled “FILL_IN_THE_BLANK“, your job is to fix the script!
- Replace the the variable “FILL_IN_THE_BLANK” with other previously defined variables in the script.
- Solutions will be posted soon– next week’s puzzles will be a lot easier!
- Original script with blanks: csvmain.py
- Working solution script: csvmain_solved.py
- Run it using “python csvmain.py igem_strain_list.csv” to see what happens–
- Instructions for argvmain.py:
Lecture 4 [download related files (tgz | zip) -- does not include PDBs or SDFs]: In Stark Review
- A review of everything we’ve done so far
- Continuing file handling (close())
- Five smaller, more manageable exercises
- puzzle0.py
- puzzle1.py
- puzzle2.py
- puzzle3.py
- 2OVC.pdb (external link) care of RCSB Protein Data Bank
- do a text search (CTRL + F or APPLE + F) for “download files”.
- puzzle4.py
- CID_6305.sdf (external link) care of The PubChem Project
- scroll to the bottom of the page and click on the button labeled “SDF”, then “3D SDF: Save”.
- Cheating with POSIX pipes (sys.stdin, sys.stdout)
- Command line arguments (sys.argv)
Lecture 5 [download slides (pdf)]: Regular Expressions and List Comprehension
- Regular expressions offer powerful degenerate string searching, extracting and replacing facilities
- List comprehension is syntactic sugar for list generation
- We also cover higher order functions and how filter, map, fold appears in Python
Future Items: OOP and Python software I’d like to cover in future incarnations of this course
- Object orientation is the backbone of coding Python GUIs
- Classes
- Most of the code is provided, students will stitch the code together (beginners won’t be fazed)
- Touches on new features for advanced students (object orientation, GUIs, modules)
- SciPy, NumPy modules for advanced mathematical functions
- PyMol software for chemistry (end user AND API)
- Chimera software (I’m currently learning it for CS683)
- Address concerns about style, efficiency: exceptions vs. conditionals (e.g. {}.has_key() vs. except KeyError)
Ed's Big Plans