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


Groups > comp.lang.python > #37348

Re: Importing class from another file

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!goblin1!goblin2!goblin.stu.neva.ru!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <kdawg44@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.010
X-Spam-Evidence '*H*': 0.98; '*S*': 0.00; 'importing': 0.04; 'importerror:': 0.05; '&quot;the': 0.07; 'subject:file': 0.07; '22,': 0.09; 'edward': 0.09; 'subdir': 0.09; 'worked,': 0.09; 'cc:addr:python-list': 0.10; 'def': 0.10; 'file,': 0.15; '__init__.py': 0.16; 'michigan': 0.16; 'namespace.': 0.16; 'subject:class': 0.16; '\xa0you': 0.16; 'wrote:': 0.17; 'thanks,': 0.18; 'jan': 0.18; 'module': 0.19; 'email addr:gmail.com&gt;': 0.20; 'trying': 0.21; 'import': 0.21; 'do.': 0.21; 'cc:2**0': 0.23; '&gt;': 0.23; 'kevin': 0.23; 'this:': 0.23; 'script': 0.24; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'leave': 0.26; '(most': 0.27; 'message-id:@mail.gmail.com': 0.27; '"do': 0.29; 'act,': 0.29; 'parent': 0.29; 'writes:': 0.29; 'url:mailman': 0.29; '"the': 0.29; 'skip:& 10': 0.29; 'class': 0.29; 'error': 0.30; '(and': 0.32; 'url:python': 0.32; 'file': 0.32; 'url:listinfo': 0.32; 'science,': 0.33; 'traceback': 0.33; 'front': 0.33; 'skip:& 20': 0.33; 'received:google.com': 0.34; 'dir': 0.35; 'pm,': 0.35; 'received:209.85': 0.35; 'there': 0.35; 'skip:_ 40': 0.35; 'add': 0.36; 'but': 0.36; 'url:org': 0.36; 'skip:m 40': 0.36; 'received:209': 0.37; 'subject:: ': 0.38; 'university': 0.38; 'fact': 0.38; 'called': 0.39; 'skip:" 10': 0.40; 'url:mail': 0.40; 'your': 0.60; 'john': 0.60; 'information': 0.63; 'today': 0.67; 'skip:_ 50': 0.69; 'business': 0.70; 'sans': 0.71; '&quot;do': 0.84; '&quot;we': 0.84; '2013': 0.84; 'email addr:panix.com': 0.84; 'excellence,': 0.84; 'mcp': 0.84; 'to:addr:gordon': 0.84; 'url:domain': 0.84; 'western': 0.89; 'bears': 0.91; 'tomorrow': 0.96
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:cc:content-type; bh=cnWNRGONrjaifgWSGiIHtNX0wAYPEdQnBh9Upg5c48A=; b=pPaKlRZ6rvtXwR8ALZeIWQMySCt06FcD863TI79yZFpqBRbd4V/0HS2pWFHRLeRMqb 3nYi4gZL7lVXiUsu0y9AUW+7zJWLDYHLoimRbrpJN3KW1iyMh28Xroy93/iHLzGwplPx a1hqbf30xAW5iZ5HuOImbyOO0jsWDoqslUty7dmEBIuqPP39T1qMf5msf8thyHf4qvUB pkJrxvbjbBlz6Q+1AtHo/4oQ79AESyVlnwCNSpEQKMPwQm5hu+omm46QCD/lLOlcgmb8 KGLX0XP0O8zBJXBLAqjpLRKMzNoshp0rqiyA7EdpdO0Xey6pqGL/cvFGuqXalcYMP1Cb dc9g==
MIME-Version 1.0
X-Received by 10.152.46.12 with SMTP id r12mr20456942lam.15.1358887484957; Tue, 22 Jan 2013 12:44:44 -0800 (PST)
In-Reply-To <kdmqcm$rd8$1@reader1.panix.com>
References <mailman.830.1358883233.2939.python-list@python.org> <kdmqcm$rd8$1@reader1.panix.com>
Date Tue, 22 Jan 2013 15:44:44 -0500
Subject Re: Importing class from another file
From Kevin Holleran <kdawg44@gmail.com>
To John Gordon <gordon@panix.com>
Content-Type multipart/alternative; boundary=bcaec5524024d4a2cf04d3e6a5e2
Cc "python-list@python.org" <python-list@python.org>
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.836.1358887486.2939.python-list@python.org> (permalink)
Lines 138
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1358887486 news.xs4all.nl 6937 [2001:888:2000:d::a6]:56629
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:37348

Show key headers only | View raw


[Multipart message — attachments visible in raw view] - view raw

Thanks, you got me straightened out.


--
Kevin Holleran
Master of Science, Computer Information Systems
Grand Valley State University
Master of Business Administration
Western Michigan University
SANS GCFA, SANS GCFE, CCNA, ISA, MCSA, MCDST, MCP

"Do today what others won't, do tomorrow what others can't" - SEALFit

"We are what we repeatedly do. Excellence, then, is not an act, but a
habit." - Aristotle


On Tue, Jan 22, 2013 at 2:47 PM, John Gordon <gordon@panix.com> wrote:

> 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"
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>

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


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