modules in diff. file

Calvin Spealman ironfroggy at gmail.com
Mon Sep 18 03:37:50 EDT 2006


On 18 Sep 2006 00:19:20 -0700, JyotiC <jyoti.chhabra at gmail.com> wrote:
> hi,
>
> i have a prog. and i want diving the code in different files.
> there will be one mail file which will call modules or
> variables(global) from differnet files
> how can i do this.
> code is very big and i it's getting difficult to manage in same file.
>
> thanx in advance

All of this is covered in any good Python tutorial, including the
official documentation. Simply move code you want to seperate into
their own python files. They will become importable modules, so foo.py
can be accessed with `import foo` from another module. Now, be careful
because you can't circularly import the modules. That means that if
you have module foo and module bar, they can't both import each other.
You'll have to take that into consideration when you seperate the code
into these modules. you can usually break up a moderately sized
project such that one main module imports all the others, and none of
them need to know about one another.

Python Tutorial - Modules
http://docs.python.org/tut/node8.html



More information about the Python-list mailing list