Academic Question

MRAB python at mrabarnett.plus.com
Sun Jan 10 20:09:17 CET 2010


Victor Subervi wrote:
> Hi;
> The following code that works:
> 
> #! /usr/bin/python
> 
> import string
> import cgitb; cgitb.enable()
> import cgi
> import MySQLdb
> import sys,os
> from sets import Set
> import fpformat
> cwd = os.getcwd()
> sys.path.append(cwd)
> from login import login
> from particulars import ourOptions
> 
> form = cgi.FieldStorage()
> store = form.getfirst('store')
> cat = form.getfirst('cat')
> id = form.getfirst('id')
> patientID = form.getfirst('patientID')
> 
> try:
>   browser = form.getfirst('browser', 'all')
> except:
>   browser = headers()
> 
A bare except, and if an exception _does_ occur, they'll be a NameError
because 'headers' isn't defined.

<slap with large halibut/>

> os.chdir('%s/..' % cwd)
> sys.path.append(os.getcwd())
> from templateFrame import top, bottom
> os.chdir(cwd)
> 
> Why doesn't it work if I move the bottom imports to the top? The form 
> values get lost, even though I chdir to cwd.
> 
I try to avoid changing the directory.



More information about the Python-list mailing list