[Tutor] odbchelper

Kent Johnson kent37 at tds.net
Fri Mar 3 14:47:38 CET 2006


Ewald Ertl wrote:
> Hi!
> 
> How have you started the script? As far as I could see, in the Chapter 1 of
> "Dive into Python", the odbchelper.py is just a script-File and not a module
> to be imported, therefore the Exception with the "ImportError".

It is both, if by "just a script-File" you mean a top-level program 
intended to be run from the command line.

If you import odbchelper it will give you access to the 
buildConnectionString() function. If you run it from the command line, 
it will also run the code after
if __name__ == "__main__":

This is pretty common - to write a module so it can be imported or used 
as a main program. The parts you want to run only from the command line 
are set off by this conditional.



More information about the Tutor mailing list