Importing modules...
Bjorn Pettersen
bjorn at roguewave.com
Fri Jul 14 19:23:29 EDT 2000
Aaron Ginn wrote:
>
> My apologies if this has been asked before. If so, please direct me to
> a FAQ. I checked Deja, but I couldn't find my answer very easily...
>
> How do I import a module that I have written? Say I have a class that
> I have created called Foo in a file stored at ~/bin/foo.py. What kind
> of command do I need to use to be able to import that class into a new
> file. I've tried the following:
>
> import '~/bin/foo.py'
>
> but this doesn't seem to be the way to do it. Do I need to set a path
> variable with ~/bin in it, and if so, how do I refer to the module?
> Is it the name of the file, i.e. foo? Or is it the name of the class,
> i.e. Foo? Do the class and the file need to have the same name? I
> don't really know how to accomplish this.
_Please_ go "read the fine manual"!
-- bjorn
ps: Python searches a list of directories in sys.path originally
initialized from the PYTHONPATH environment variable. The import
statement only mentions the name of the module, without quotes or
extensions; that way the import framework has a chance to do
interesting/important stuff before your module is loaded.
More information about the Python-list
mailing list