1

Which is the best: create the modules and put them in a separate file and import them or put them all together in the same file?

Is there any significant difference?

Sharjeel Aziz
  • 8,495
  • 5
  • 38
  • 37
scripts
  • 1,452
  • 1
  • 19
  • 24
  • module == file. I can't parse the question. A module **is** a "separate file". How can you put modules (which are files) into "the same file"? – S.Lott Oct 20 '10 at 20:33
  • 1
    @S.Lott: My best guess is that he is looking if he should write every thing in one file or decompose it in modules. The same discussion as .py and .pyc ... – pyfunc Oct 20 '10 at 20:36
  • 1
    possible duplicate of [How many Python classes should I put in one file?](http://stackoverflow.com/questions/106896/how-many-python-classes-should-i-put-in-one-file) – S.Lott Oct 20 '10 at 20:39
  • Duplicate of all of these: http://stackoverflow.com/search?q=%5Bpython%5D+class+module – S.Lott Oct 20 '10 at 20:39
  • 1
    possible duplicate of [Organizing Python classes in modules and/or packages](http://stackoverflow.com/questions/3842616/organizing-python-classes-in-modules-and-or-packages) – Greg Hewgill Oct 20 '10 at 20:52

1 Answers1

3

Same as disscussion on .py and .pyc. Having modules allows you to load them faster through precompiled modules. How ever negligible, this adds to performance. Though execution speed remains the same.

Please look at the following for a detailed answer. Repeating it is not useful.

[Edit:]

Decomposing the solution in modules is always better for future maintenance and enhances readability. The performance is almost always not the primary reason for decomposition of solution into various modules.

Community
  • 1
  • 1
pyfunc
  • 65,343
  • 15
  • 148
  • 136