Importing class from another file

Kevin Holleran kdawg44 at gmail.com
Tue Jan 22 20:33:45 CET 2013


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20130122/be30a854/attachment.html>


More information about the Python-list mailing list