0

Not sure if my python question is titled correctly, but I get a NameError: global name 'someOtherClass' is not defined error when I try to call a method that uses a module imported through the __init__ function of my class.

class myClass
    def __init__(self):
        if is_64b:
            exit()
        else:
            import someOtherClass

    def myMethod(self, param1, param2, param3):
        return someOtherClass.someMethod(param1, param2, param3)

from myFolder.myClassFileName import myClass
myObj = myClass()
value = myObj.myMethod(p1, p2, p3)
Colin
  • 415
  • 3
  • 14
  • You are importing the name `someOtherClass` into the `__init__` method. – Stephen Rauch Jun 09 '18 at 21:58
  • @StephenRauch I do not really understand what this implies. Are you saying that it is not possible to do? If I don't import into `__init__`, where can I import it such that all other methods of the class can see the import? – Colin Jun 10 '18 at 00:07
  • You will need to understand namespaces for this to make sense, Which is why I closed as duplicate for namespaces. Go read the answers (especially the top answer) at the duplicate question. – Stephen Rauch Jun 10 '18 at 00:09
  • imports are generally done at the very top of the file unless you have special needs. – Stephen Rauch Jun 10 '18 at 00:11

0 Answers0