On Thu, Mar 19, 2015 at 11:11 AM <[email protected]> wrote:

> Hi yo,
>
> I have a long python script, over 1000 lines now and growing. I was
> thinking would it be wise to start splitting this big program up into
> smaller python files. I have two questions:
>
> 1) would this increase the time it takes to run the script. Say it had to
> load 10 separate python scripts.
>

Technically it would be false to say it didn't add at least some form of
extra work since at first import Python would have to do more filesystem
operations. But it isn't something you should really be concerned with in
terms of structuring your application. Especially since they will all be in
the same PYTHONPATH and you would be benefiting from filesystem caching.

Basically...no don't worry about this.


>
> 2) how do you do it?, could someone explain this with a simple example?
>
>
It isn't so much of a matter of starting to write a script and the going
"well I have hit 1000 lines, so it's time to split!". What you should
probably focus on is grouping common functionality into modules. This will
allow you to continue to do related work within a given module as opposed
to jumping between logic that is simply just split for the sake of
splitting it. Also it promotes re-usability, because you may have some
interesting operations that can be imported by some other app, without
needing dependencies that some of your other modules might require. Let's
say you require a certain GUI library in part of your application, but you
also have a bunch of great file parsing logic. If you kept them both in the
same module, then other applications would depend on having the GUI library
available to even import the code to get at the file parsing. And the two
may be completely unrelated.

An example would be, say if you were developing a GUI application, to group
together logic for various views, and to keep your business logic separate
as well. Such as the logic that may talk to a database, or interact with a
network API.



> thanks,
> Sam
>
> --
> You received this message because you are subscribed to the Google Groups
> "Python Programming for Autodesk Maya" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/python_inside_maya/55b56fbf-0525-427b-b8b8-
> a21028df5bc5%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA3-By7Afv1P-txrfJdLRoZHhoEvsJvooAKL9duwPJ-07A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to