Skip to content Skip to sidebar Skip to footer

Python Cross Module Variables

I realize there are other threads addressing this problem but as I am fairly new to 'Classes' and have already constructed my class structure ... I would like to find a method that

Solution 1:

NameVar is not defined in NameAssign; it only exists within NameAssign.NameWorks.InputNames() as a local variable. The easiest way to fix this is to define it in NameAssign at the global level.

Edit:

It turns out that this is what you want to do:

NameResult.py

import NameAssign

namelist = NameAssign.NameWorks(['harry', 'betty', 'sam'])
print namelist.InputNames()  # or print(...) for Py3k

NameAssign.py

classNameWorks(object):def__init__(self, names):
    self.names = names

  defInputNames(self):
    returnself.names

Post a Comment for "Python Cross Module Variables"