importing a user file in Python
David Tweet
davidtweet at gmail.com
Sat Dec 1 02:51:50 EST 2007
You have options:
1) Have the file in your current working directory, in which case
it's just "import odbchelper".
2) Change your PYTHONPATH in your shell, adding a line like this to
your bashrc perhaps:
export PYTHONPATH=$PYTHONPATH:/home/jw/diveintopython-5.4/py
... and do the same import line in your code once you've
sourced your bashrc again.
On Nov 30, 2007 11:42 PM, waltbrad <waltbrad at hotmail.com> wrote:
> Hello. I'm brand new to Python. I'm running a Kubuntu system and
> working through the "diveintopython" tutorial. The author of that
> gives these instructions:
>
> >>> import odbchelper
> >>> params = {"server":"mpilgrim", "database":"master", "uid":"sa", "pwd":"secret"}
> >>> print odbchelper.buildConnectionString(params)
> server=mpilgrim;uid=sa;database=master;pwd=secret
> >>> print odbchelper.buildConnectionString.__doc__
> Build a connection string from a dictionary
> Returns string.
>
>
> I've tried to enter this into the interpreter but the very first
> instruction:
>
> >>>import odbchelper
>
> gives me this:
>
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> ImportError: No module named odbche
>
> I've tried to enter the pathname:
>
> >>> import /home/jw/diveintopython-5.4/py/odbchelper.py
>
> and I get this error:
>
> >>> import /home/jw/diveintopython-5.4/py/odbchelper.py
> File "<stdin>", line 1
> import /home/jw/diveintopython-5.4/py/odbchelper.py
> ^
> SyntaxError: invalid syntax
> >>>
>
>
> Where on my system do I have to place these files before the
> interpreter will import them?
>
> Thanks.
> --
> http://mail.python.org/mailman/listinfo/python-list
>
--
-David
More information about the Python-list
mailing list