ActiveState Python won't call module function.

Mel Wilson mwilson at the-wire.com
Sat Nov 29 22:11:42 CET 2003


In article <bqatc6$1pv$1 at lust.ihug.co.nz>,
"Glenn Reed" <dont_use at nowhere.com> wrote:
>Hi,
>
>This is probably a really easy question and I apologize if it is already
>covered in some faq somewhere.
>
>These are my two source files:
>------- module1.py -------------
>class module2:
>    def __init__(self):
>        self.x=23
>        self.y=14
>        self.z=33
>        self.x1=self.x=3
>
>#thisClass=module2()
># I added the above line in just to test it works here and it does.
>------- tmod.py ---------------
># Test Module
>import module1
>
>thisClass = module2()
>
>----------------------------------------------
>
>It generates the following error:
>Traceback (most recent call last):
>  File
>"C:\Python22\Lib\site-packages\Pythonwin\pywin\framework\scriptutils.py",
>line 301, in RunScript
>    exec codeObject in __main__.__dict__
>  File "C:\My Documents\PythonSrc\Temp\tmod.py", line 4, in ?
>    thisClass = module1()
>NameError: name 'module2' is not defined


   And it isn't.  'module1.module2' is defined in your main
module, though.

    thisClass = module1.module2()

should work fine.  (Hint: module1 doesn't have to import itself
to get the symbols it defines.)

        Regards.        Mel.




More information about the Python-list mailing list