Calder Coalson wrote:
> Ok, I have a program with multiple different states, but it does, (to 
> some extent) run linearly.  All I want to do, is to be able to take 
> chunks of the program and put it in separate files so I don't have to 
> scroll through a couple thousand lines of stuff every time I want to 
> find the right part of the code.  I guess I could just right a master 
> program that takes all of the text files and smashes them together and 
> then runs it.  But is there any other way to do it?
That is exactly what modules and imports let you do.

It sounds like maybe your program might not be very well organized. 
Maybe you need to break up your program into functions or classes. Then 
some of these functions or classes could be put into separate modules.
>
> The problem with modules is that they run in their own Python shell.
No, they run in the same process as the module that imports them.
>   Libraries I've imported in the main program and variables I've 
> defined there aren't accessible in the module.  What I really need is 
> just a
> run_file("/Users/calderco/Pygame/T-Board/thefile.py")
Right, modules do have their own namespace. You can import the modules 
you need. Variables you need access to can be passed as parameters to 
functions defined in a module.

A tutorial on modules:
http://www.freenetpages.co.uk/hp/alan.gauld/ (Modules and Functions section)

Kent
>
> I guess the assimilator program shouldn't take that long, but it 
> really seems like there should be an easy way to do this.
>
> Thanks for the help,
> -Calder
>
>
> On May 20, 2007, at 6:37 AM, Kent Johnson wrote:
>
>> Calder Coalson wrote:
>>> I've tried import, but that  doesn't work because the thing has to 
>>> be completely independent.  All  I want to do is split up my file 
>>> into multiple files,
>>
>> These requirements seem a bit contradictory. If you have one program 
>> that you want to split into multiple modules, import is the usual 
>> mechanism for doing that. What kind of independence are you looking 
>> for? If you truly need the programs to run in separate processes then 
>> the other answers are on the right track. Otherwise I'm not so sure 
>> what it is you need.
>>
>> Kent
>
>

_______________________________________________
Pythonmac-SIG maillist  -  Pythonmac-SIG@python.org
http://mail.python.org/mailman/listinfo/pythonmac-sig

Reply via email to