1) Python code is organized into modules (i.e. libraries in files).
To include a module use:
import modulename # the file must be modulename.py in the current directory (or a special "known" directory)
To use a function in that file later on, say
modulename.functionname()
2) To catch an error and have it handled by an error handler, say:
try:
code # the word code won't execute, this will be an error
except:
# error handling code
pass # pass is a do-nothing statement
for example:
try:
print 1+1
print 1 + a # a is not defined, this will throw an error
except:
print "Whoops"
Output:
2
Whoops
3)
To create a class that inherits from another class, just like java, it;s:
class myClass(parentclass):
code
where parentclass is the class we are derived from.
4) Opening a file (seen in the example code):
f = open(finame,mode)
text = f.read() # reads ALL of the file into variable text
f.close()
or
f = open(finame,mode)
text = f.readlines() # reads ALL of the file returning a list where each line
# is one element of the array
f.close()