Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #14931 > unrolled thread
| Started by | candide <candide@free.invalid> |
|---|---|
| First post | 2011-10-24 21:51 +0200 |
| Last post | 2011-10-24 20:38 +0000 |
| Articles | 2 — 2 participants |
Back to article view | Back to comp.lang.python
Importing a module from a non-cwd candide <candide@free.invalid> - 2011-10-24 21:51 +0200
Re: Importing a module from a non-cwd John Gordon <gordon@panix.com> - 2011-10-24 20:38 +0000
| From | candide <candide@free.invalid> |
|---|---|
| Date | 2011-10-24 21:51 +0200 |
| Subject | Importing a module from a non-cwd |
| Message-ID | <4ea5c1da$0$3708$426a74cc@news.free.fr> |
Hi, It's easy to open a file not located in the current working directory (cwd). But how about importing a module? For instance, suppose I have a file, say my_file.py, located in the cwd, say /home/candide/ and suppose the module to be imported, say my_module.py, is located in the /home/candide/foo/ directory. How my_file.py can import the my_module.py module ? Thanks
[toc] | [next] | [standalone]
| From | John Gordon <gordon@panix.com> |
|---|---|
| Date | 2011-10-24 20:38 +0000 |
| Message-ID | <j84ica$94j$1@reader1.panix.com> |
| In reply to | #14931 |
In <4ea5c1da$0$3708$426a74cc@news.free.fr> candide <candide@free.invalid> writes:
> For instance, suppose I have a file, say my_file.py, located in the cwd,
> say /home/candide/ and suppose the module to be imported, say
> my_module.py, is located in the /home/candide/foo/ directory.
> How my_file.py can import the my_module.py module ?
If PYTHONPATH and/or sys.path contain /home/candide/foo/, then you should
be able to:
import my_module
Or, if foo/ is a real module (i.e. it contains an __init__.py file), this
should work:
import foo.my_module
--
John Gordon A is for Amy, who fell down the stairs
gordon@panix.com B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web