2 Replies - 702 Views - Last Post: 07 August 2012 - 11:59 AM Rate Topic: -----

#1 zedth2  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 121
  • Joined: 14-September 09

Multiple file module.

Posted 07 August 2012 - 09:44 AM

So right now I have a module with seaverl classes in it. If I put all those classes the __init__.py file it's quickly going to be well over a thousand lines of code. Which is going to be a nightmare to maintain.So I was looking for a way to put all those classes into seperate files without making the module have sub modules.The only way I can think of doing that is by using sudeoprivate. I was thinking of doing this.

module/
__init__.py
_ClassA.py
_ClassB.py
_ClassC.py

and each class would be in it's respected file and in the __init__.py file would be


class ClassA(_ClassA):
    pass
    
class ClassB(_ClassB):
    pass
    



And so on for each class. But my question is, is this "pythonetic?" Or is this just a messy way of making
a bigger mess less messy.

Thanks in advance.

Is This A Good Question/Topic? 0
  • +

Replies To: Multiple file module.

#2 atraub  Icon User is offline

  • Pythoneer
  • member icon

Reputation: 758
  • View blog
  • Posts: 2,010
  • Joined: 23-December 08

Re: Multiple file module.

Posted 07 August 2012 - 09:52 AM

I'm not understanding. It sounds like you put a lot of classes into 1 module... Why not separate the classes into their own separate modules?
Was This Post Helpful? 0
  • +
  • -

#3 zedth2  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 121
  • Joined: 14-September 09

Re: Multiple file module.

Posted 07 August 2012 - 11:59 AM

All of these classes are related to each other very strongly, so strongly in fact that I'm getting circular imports. If I put all the classes in the modules __init__.py file then the file is going to be very large and close to unmanageable by the time the code is finished so I'm trying to put each class in it's own file but keep it under the module. For example if I was writing this in another language with a namespace I'd have all these classes in that namespace. It seems illogical to me that each class have its own module. All the module work together so I think they should be on the same level. So the basic question is can I split a module into separate files? If my understand of python is correct I can not because each file is a separate module. So basically what I'm planing on doing is having several different files in the module that are sudoprivated out and the parent module contains classes that inherit the classes that are in the other files. This way each class gets its own file but to the user of the module they still appear to be at the top of the module. But is this in accordance with python? Or is a bad way of accomplishing something? If that makes any more. I'm fairly new to python, I'm teaching it to myself for a summer project. I just finished Mark Lutz's book, Learning Python.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1