Dec-11-2016, 04:39 PM
(Dec-11-2016, 03:34 PM)PickyBiker Wrote: I'm struggling with the overall structure of a python program. The following code works (as-is), but I'm not sure this is the way to let a main program function access class elements. If I move the class Test to a test.py file and then import that file it doesn't work so there must be a better way.You still need to create an object like you did in main(). Also note that the content in your if condition (calling main) if __name__ == '__main__' only runs when this scripts is ran directly, not imported. The creation of objects will normally be in the script you import this from, not inside the module itself.
The import being used is: import test
What am I doing wrong?
test is the name of your class. If you name this file "my_module" you would import it as
import my_moduleand then used as
my_object = my_module.test()or import the class only
from my_module import testand then used as
my_object = test()see here for more info
http://python-forum.io/Thread-Basic-Modules-part-2
Recommended Tutorials: