Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #37342
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!news-xxxfer.readnews.com!news-out.readnews.com!transit3.readnews.com!panix!gordon |
|---|---|
| From | John Gordon <gordon@panix.com> |
| Newsgroups | comp.lang.python |
| Subject | Re: Importing class from another file |
| Date | Tue, 22 Jan 2013 19:47:34 +0000 (UTC) |
| Organization | PANIX Public Access Internet and UNIX, NYC |
| Lines | 36 |
| Message-ID | <kdmqcm$rd8$1@reader1.panix.com> (permalink) |
| References | <mailman.830.1358883233.2939.python-list@python.org> |
| NNTP-Posting-Host | panix3.panix.com |
| X-Trace | reader1.panix.com 1358884054 28072 166.84.1.3 (22 Jan 2013 19:47:34 GMT) |
| X-Complaints-To | abuse@panix.com |
| NNTP-Posting-Date | Tue, 22 Jan 2013 19:47:34 +0000 (UTC) |
| User-Agent | nn/6.7.3 |
| Xref | csiph.com comp.lang.python:37342 |
Show key headers only | View raw
In <mailman.830.1358883233.2939.python-list@python.org> Kevin Holleran <kdawg44@gmail.com> writes:
> I have a class called My_Class in a subdir called Sub_Dir.
> in My_Class.py is the following
> class My_Class_Connector:
> def __init__(self,un,pw,qs_srv="domain.com"):
> self.username = un
> self.password = pw
> Then I am trying to call from a script in the parent dir like this:
> from Sub_Dir.My_Class import *
> q_api = My_Class.My_Class_Connector(string1,string2)
Even if your import had worked, this would be wrong. You're importing
everything from Sub_Dir.My_Class, so My_Class_Connector is in the current
namespace. You don't need to add "My_Class." on the front (and in fact
it's an error to do so.)
> Traceback (most recent call last):
> File "testing.py", line 1, in <module>
> from Sub_Dir.My_Class import *
> ImportError: No module named Sub_Dir.My_Class
Is there a file named __init__.py in Sub_Dir? A directory must contain
that file in order to be considered a "module". (If you don't know what
to put in the file, just leave it empty.)
--
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 | Next in thread | Find similar | Unroll thread
Importing class from another file Kevin Holleran <kdawg44@gmail.com> - 2013-01-22 14:33 -0500
Re: Importing class from another file John Gordon <gordon@panix.com> - 2013-01-22 19:47 +0000
Re: Importing class from another file Kevin Holleran <kdawg44@gmail.com> - 2013-01-22 15:44 -0500
csiph-web