Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python structure question
#1
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.

The import being used is: import test

What am I doing wrong?

class Test(object):
    def __init__ (self):
        pass
    class a(object):
        def __init__ (self):
            print("a")
    class b(object):
        def __init__ (self):
            print("b")

def    main():
    t = Test()
    t.a()
    t.b()
    print("Done")

if __name__=="__main__":
    main()
Reply


Messages In This Thread
Python structure question - by PickyBiker - Dec-11-2016, 03:34 PM
RE: Python structure question - by metulburr - Dec-11-2016, 04:39 PM
RE: Python structure question - by PickyBiker - Dec-11-2016, 05:02 PM
RE: Python structure question - by metulburr - Dec-11-2016, 05:35 PM
RE: Python structure question - by PickyBiker - Dec-11-2016, 05:37 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Python Project Structure for Modularity and Reusability with Multiple Entry Points b19wh33l5 0 176 Apr-24-2024, 12:21 PM
Last Post: b19wh33l5
  python project structure anne 1 1,763 Aug-01-2020, 07:17 PM
Last Post: deanhystad
  Nested Data structure question arjunfen 7 4,292 Feb-22-2019, 02:18 PM
Last Post: snippsat
  Call functions recursively in tree structure using python dubru 1 2,306 Feb-15-2019, 06:43 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020