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


Groups > comp.lang.python > #37436

Re: Importing class from another file

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!us.feeder.erje.net!newsfeed.straub-nv.de!reality.xs3.de!nntp-feed.chiark.greenend.org.uk!ewrotcd!news.nosignal.org!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <tm@tobix.eu>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'interpreter': 0.04; 'beginner': 0.05; 'importerror:': 0.05; 'class,': 0.07; 'see:': 0.07; 'subject:file': 0.07; 'python': 0.09; 'etc).': 0.09; 'sure,': 0.09; 'passing': 0.15; '(double': 0.16; '__init__.py': 0.16; 'instantiate': 0.16; 'received:188.40.28': 0.16; 'received :your-server.de': 0.16; 'subject:class': 0.16; 'wrote:': 0.17; 'module': 0.19; 'bit': 0.21; 'import': 0.21; 'assignment': 0.22; 'kevin': 0.23; 'script': 0.24; 'header:In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'skip:m 30': 0.26; '(most': 0.27; 'list:': 0.27; 'object,': 0.27; 'parent': 0.29; 'url:mailman': 0.29; 'class': 0.29; 'url:python': 0.32; 'file': 0.32; 'url:listinfo': 0.32; 'asked': 0.33; 'traceback': 0.33; 'to:addr :python-list': 0.33; 'hi,': 0.33; 'url:org': 0.36; 'modules': 0.36; 'should': 0.36; 'execute': 0.37; 'subject:: ': 0.38; 'url:docs': 0.38; 'to:addr:python.org': 0.39; 'called': 0.39; 'skip:" 10': 0.40; 'url:mail': 0.40; 'think': 0.40; 'your': 0.60; 'skip:u 10': 0.60; 'details': 0.63; 'more': 0.63; 'information:': 0.74; 'played': 0.84; 'url:tutorial': 0.93; 'have.': 0.95
Date Wed, 23 Jan 2013 10:53:21 +0100
From "Tobias M." <tm@tobix.eu>
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130106 Thunderbird/17.0.2
MIME-Version 1.0
To python-list@python.org
Subject Re: Importing class from another file
References <CAN4UfGybBW0m7041puAZC8B2Nsgh0VKK8bSqSfbMSzpHvZHxTw@mail.gmail.com>
In-Reply-To <CAN4UfGybBW0m7041puAZC8B2Nsgh0VKK8bSqSfbMSzpHvZHxTw@mail.gmail.com>
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-Authenticated-Sender tm@tobix.eu
X-Virus-Scanned Clear (ClamAV 0.97.5/16554/Wed Jan 23 06:47:19 2013)
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.877.1358934808.2939.python-list@python.org> (permalink)
Lines 33
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1358934808 news.xs4all.nl 6876 [2001:888:2000:d::a6]:42279
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:37436

Show key headers only | View raw


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


Thread

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

csiph-web