Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!news.glorb.com!news-out.readnews.com!news-xxxfer.readnews.com!panix!gordon From: John Gordon Newsgroups: comp.lang.python Subject: Re: Importing a module from a non-cwd Date: Mon, 24 Oct 2011 20:38:34 +0000 (UTC) Organization: PANIX Public Access Internet and UNIX, NYC Lines: 23 Message-ID: References: <4ea5c1da$0$3708$426a74cc@news.free.fr> NNTP-Posting-Host: panix1.panix.com X-Trace: reader1.panix.com 1319488714 9363 166.84.1.1 (24 Oct 2011 20:38:34 GMT) X-Complaints-To: abuse@panix.com NNTP-Posting-Date: Mon, 24 Oct 2011 20:38:34 +0000 (UTC) User-Agent: nn/6.7.3 Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:14935 In <4ea5c1da$0$3708$426a74cc@news.free.fr> candide 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"