Ed's Big Plans

Computing for Science and Awesome

Python Crash Course

without comments

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)
  • 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:
      1. Run mainx.py
      2. Fill in any Four fields out of Five fields with numbers
      3. 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:
      1. Run argvmain.py using “python argvmain.py
      2. Now try running it with a few arguments, e.g. “python argvmain.py The cow eats grass!
      3. Look at the script and notice that the sys.argv variable is a list that contains the arguments!
    • Instructions for csvmain.py:
      1. 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
      2. There are several blanks in the file labelled “FILL_IN_THE_BLANK“, your job is to fix the script!
      3. Replace the the variable “FILL_IN_THE_BLANK” with other previously defined variables in the script.
      4. Solutions will be posted soon– next week’s puzzles will be a lot easier!

Lecture 4 [download related files (tgz | zip) — does not include PDBs or SDFs]: In Stark Review

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)

Written by Eddie Ma

December 22nd, 2009 at 11:29 am

Posted in