getting equal behavior for scripts and modules ?

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Mon Oct 12 19:01:12 EDT 2009


En Sun, 11 Oct 2009 18:07:30 -0300, Stef Mientki <stef.mientki at gmail.com>  
escribió:
> Gabriel Genellina wrote:
>> En Sun, 11 Oct 2009 14:50:31 -0300, Stef Mientki  
>> <stef.mientki at gmail.com> escribió:
>>
>>> Now I finally (after 2 years) knowing there's a difference between  
>>> modules and scripts,
>>> I want to guarantee that I always get the same functional behavior.
>>
>> In Delphi terms, you have units (.pas) and programs (.dpr). You can't  
>> add a .dpr to the Uses clause of an unit. In case you have some code in  
>> a .dpr that you want to use somewhere else, you move it into a new unit  
>> and Use it from both places.
> I never ever edited a dpr file, it's created fully automatically (don't  
> know what is in it) and I even think you don't need to use it at all.
> In Delphi there's a "main unit" and other units, but it's up to the  
> programmer which unit is set as the "main unit".

The main unit is the program (the one that starts with the keyword  
'program' instead of 'unit', and has no interface). But if you don't know  
what a program is, explaining the analogy is pointless.

>> Too much hassle and magic for what should be a non-issue.
>>
> If you choose for a strict separation between "script" and "module", I  
> guess it's indeed a non-issue.
> Using software as if it was Lego, needs either a detection or prevention  
> of effects of the difference between script and module.

Just remember to put a guard like this:

if __name__ == '__main__':

around anything you don't want executed when the code is imported (as  
opposed to being run as a script/program)

-- 
Gabriel Genellina




More information about the Python-list mailing list