1

I have two modules misc.py and main.py and would like to define all classes present in misc.py in main.py.

Below is the code

#misc.py

class dummy:
    def __init__(self):
        pass
    def dummyPrint(self):
        print "Welcome to python"

#main.py

 import misc
 dummyObj = dummy()
 dummyObj.dummyPrint()

Is this the right way to go ? I do not see any output i.e., Welcome to python

$python misc_main.py misc.py

EDIT: I added the statement from misc import dummy and i am getting the following error

$python misc_main.py main.py

Traceback (most recent call last):
File "misc_main.py", line 5, in <module>
dummyObj =  dummmy()
NameError: name 'dummmy' is not defined
1
  • from misc import dummy Commented Jun 25, 2014 at 1:27

1 Answer 1

5

When you do the following command, you are calling misc_main.py from the interpreter with misc.py as an argument.

python misc_main.py misc.py

Since misc_main is not reading command line arguments, this is equivalent to

python misc_main.py

I am surprised that you do not get errors, in either case. You need to import the actual class if you want to get output.

from  misc import dummy

dummyObj = dummy()
dummyObj.dummyPrint()

Note, I am assuming your main file is actually in called misc_main.py rather than main.py as you have stated in your question. Otherwise you are not invoking the correct file.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.