[wingide-users] global imports

Graham Wideman initcontact at grahamwideman.com
Wed Jun 8 14:22:25 MDT 2011


George:

I am not completely clear what you are trying to achieve, but will take a crack at it.

I *think* what you are doing is using a single consistent Subroutines module, where the subroutines depend on a large number of parameters, and the specific set of parameters are to be selected by the particular main module for a particular project.

Yet you say: "Subroutines has no clue of what it importing...."

I am taking this to mean that Subroutines ought not to be hard-coded as to *which* particular parameters modules it's importing, BUT presumably within the individual subroutines it knows the names of all the individual parameter variables (functions or whatever) in order to be able to call them, right?    Ie: The names of the individual param variables are at least consistent across different versions of a parameter file, right?

Anyhow, assuming that is on track...

Instead of using relatively advanced Python to fiddle with the list of globals, why not revise each param file into an object, so that the entire set of variables (or functions or whatever) in that param file can be referenced through a single object variable.

Then you can use main as the single place where you import the particular set of say three param files for that project, and either assign them to three global variables in Subroutines, or pass them to an init routine in Subroutines which assigns them to module globals.

Within Subroutines, you would need to prefix each use of a param variable with the name of the applicable module global, but that's a one-time edit, and makes it very clear where each value is coming from (Ie: I'm advocating this as an improvement over just having loads of individual globals).

Thoughts?

-- Graham



More information about the wingide-users mailing list