getting equal behavior for scripts and modules ?

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Sun Oct 11 14:44:36 EDT 2009


En Sun, 11 Oct 2009 14:50:31 -0300, Stef Mientki <stef.mientki at gmail.com>  
escribió:

> I do agree that circular references should preferable be avoided.
>
> In languages like Delphi, you get an error message, trying to use  
> circular references,
> but solving them in large programs with a lot of history can be very  
> painful.
>
> 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.

Translated to Python terms: you have modules and scripts. You shouldn't  
import a script from a module. In case you have some code in a script that  
you want to use somewhere else, move it into a new module and import it  
 from both places.

Note the change between "can't" and "shouldn't". Delphi just won't let you  
import the main program from another place; Python does, with strange  
effects, but you should not do that. You can avoid the temptation by  
naming your scripts with another extension (or no extension at all).

> I found 2 solutions to realize the above.
> [...]

Too much hassle and magic for what should be a non-issue.

-- 
Gabriel Genellina




More information about the Python-list mailing list