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


Groups > comp.lang.python > #37340

Importing class from another file

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed2.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.002
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'error:': 0.05; 'importerror:': 0.05; 'subject:file': 0.07; 'python': 0.09; 'etc).': 0.09; 'script,': 0.09; 'subdir': 0.09; 'def': 0.10; 'instantiate': 0.16; 'subject:class': 0.16; 'module': 0.19; 'to:name:python-list@python.org': 0.20; 'trying': 0.21; 'bit': 0.21; 'import': 0.21; 'assignment': 0.22; 'help.': 0.22; 'kevin': 0.23; 'this:': 0.23; 'script': 0.24; '(most': 0.27; 'object,': 0.27; 'message-id:@mail.gmail.com': 0.27; 'parent': 0.29; 'skip:& 10': 0.29; 'class': 0.29; 'classes': 0.30; 'worked': 0.30; 'file': 0.32; 'running': 0.32; 'traceback': 0.33; 'to:addr:python-list': 0.33; 'skip:& 20': 0.33; 'received:google.com': 0.34; 'thanks': 0.34; 'dir': 0.35; 'doing': 0.35; 'received:209.85': 0.35; 'skip:_ 40': 0.35; 'skip:m 40': 0.36; 'received:209': 0.37; 'sure': 0.38; 'to:addr:python.org': 0.39; 'hello,': 0.39; 'called': 0.39; 'skip:" 10': 0.40; 'skip:_ 50': 0.69; 'played': 0.84; 'url:domain': 0.84
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:date:message-id:subject:from:to :content-type; bh=zxreJm23aRMq6GjaWLS2ZS0xSi9vnEC381l39ub24EE=; b=Bg/4cZ2wFNKjM7teUZy2Xx073R2zpa2S/4/vJ7MUmUBQjPhO0FZQCtXgmqUTg7tBa0 R0QXm/r+j8D6gUYUPvgEVsF5FP02bAmabBSz1zTJsJT8sIehAHyQhK6ZGo0hbfJdQW81 vef785bGq2sxTL/w3PUoRoFPcgqREoGm7ZLjwe5NyAHd6YKJAk8nx+Q2wRXRasAfJurY R4Ub03AaAHmkDV6WDAN1AmcuHk2h7C1qTl2/c/0u8iyG+YScUxpkyMJujb0kKyvQw7kD Cm5shZnTflh0OdIEmDg2RRBjeCZQThRY0RA2tmwXIqPcH7MYg55gWRGtQAP9N0AL5eSz ZXpQ==
MIME-Version 1.0
X-Received by 10.112.16.203 with SMTP id i11mr9666287lbd.135.1358883225281; Tue, 22 Jan 2013 11:33:45 -0800 (PST)
Date Tue, 22 Jan 2013 14:33:45 -0500
Subject Importing class from another file
From Kevin Holleran <kdawg44@gmail.com>
To "python-list@python.org" <python-list@python.org>
Content-Type multipart/alternative; boundary=f46d0401f99def24b904d3e5a792
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.830.1358883233.2939.python-list@python.org> (permalink)
Lines 91
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1358883233 news.xs4all.nl 6929 [2001:888:2000:d::a6]:58180
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:37340

Show key headers only | View raw


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

Hello,

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)


I have not worked much with Python classes so I am not sure what I am doing
wrong.  When running this from my script, I get the following error:


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


I have played around a bit with the calls (removing the My_Class in the
q_api assignment to instantiate the object, etc).


Thanks for any help.


Kevin

Back to comp.lang.python | Previous | NextNext 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