Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #37436
| Date | 2013-01-23 10:53 +0100 |
|---|---|
| From | "Tobias M." <tm@tobix.eu> |
| Subject | Re: Importing class from another file |
| References | <CAN4UfGybBW0m7041puAZC8B2Nsgh0VKK8bSqSfbMSzpHvZHxTw@mail.gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.877.1358934808.2939.python-list@python.org> (permalink) |
Hi, Kevin Holleran wrote: > > 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 > > Make sure, the script you execute by passing it to the python interpreter is in the parent directory of Sub_Dir. Additionaly put an empty file called __init__.py (double underscores!) in Sub_Dir if you don't already have. This is necessary to use Sub_Dir as a package and import modules from it. For more details see: http://docs.python.org/3.3/tutorial/modules.html#packages > I have played around a bit with the calls (removing the My_Class in > the q_api assignment to instantiate the object, etc). > When using "from...import" on the module that contains the class, you can use the class without the package identifier: q_api = My_Class_Connector(string1,string2) For your information: I think beginner questions like this one should be asked on the tutor list: http://mail.python.org/mailman/listinfo/tutor
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Importing class from another file "Tobias M." <tm@tobix.eu> - 2013-01-23 10:53 +0100
csiph-web