Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #14935

Re: Importing a module from a non-cwd

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 <gordon@panix.com>
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 <j84ica$94j$1@reader1.panix.com> (permalink)
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

Show key headers only | View raw


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"

Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread


Thread

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

csiph-web