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


Groups > comp.lang.python > #37436 > unrolled thread

Re: Importing class from another file

Started by"Tobias M." <tm@tobix.eu>
First post2013-01-23 10:53 +0100
Last post2013-01-23 10:53 +0100
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Importing class from another file "Tobias M." <tm@tobix.eu> - 2013-01-23 10:53 +0100

#37436 — Re: Importing class from another file

From"Tobias M." <tm@tobix.eu>
Date2013-01-23 10:53 +0100
SubjectRe: Importing class from another file
Message-ID<mailman.877.1358934808.2939.python-list@python.org>
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

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web