[wingide-users] global imports

Adi J. Sieker adi at sieker.io
Wed Jun 8 15:08:20 MDT 2011


On 08/06/11 22:33, Mclam, GeorgeX wrote:
> Hi Paul.
>
> Thank you for the reply.
>
>> I believe you may already have a list of names you want to steal from
>> the modules; I presume your current import statement in subroutines.py
>> looks like
>>
>> from<something>  import w,x,y,z, ...
>
> Nope.  My subroutines.py file presently looks something like:
> # subroutines.py
> from project_conn import *
> from project_eset import *
> from project_parm import *
>

how does subroutine currently know how to use the project modules?

can you give a simple example of how it currently works maybe then it's 
possible to give some other suggestions.

> subroutines does not know what is being imported and needs everything.
if it doesn't know what is being imported I actually really doubt it 
needs everything and if it does there must be a "better" way to do things.

> Objects are added all the time to projects.  The idea is to avoid any
> editing of subroutines (the variables are in the project files, not
> subroutines).
>
>
>> No they are NOT the names.  They are the modules themselves.
>
> That's too bad.  My list of objects is simply too large and varies too
> much to call out each and every item individually.
>
> I am looking to make things easier than what I presently have but w/o
> the need to have so many copies of subroutines.  As soon as I have to
> create a list of all the objects, it makes no sense.  It would be one
> thing if the list was final, but it is constantly changing.
>
>
> Thank you for your suggestions.  I can see there are other ways to
> accomplish what the present import (or from) statements do.  I still
> feel this should be a common situation for anyone who wants to re-use
> the same code over and over w/o complexities or constant editing.
>
> George
>
>
>
> -----Original Message-----
> From: Paul Du Bois [mailto:dubois at doublefine.com]
> Sent: Wednesday, June 08, 2011 12:25 PM
> To: Mclam, GeorgeX; wingide-users at wingware.com
> Subject: RE: [wingide-users] global imports
>
>>>> def init(a, b, c):
>>>>   for module in a,b,c:
>>>>     globals().update(module.__dict__)
>>
>> Hmmm.... so a, b&  c are the names of modules that I want to "import",
> correct?
>> If so, this just might work.  I'll have to check the docs on this one.
>
> No they are NOT the names.  They are the modules themselves.  Re-read
> the original code snippet:
>
> # project_main.py
> import parameter1, parameter2, parameter3
> import subroutines
> subroutines.init(parameter1, parameter2, parameter3)
>
> I believe you may already have a list of names you want to steal from
> the modules; I presume your current import statement in subroutines.py
> looks like
>
> from<something>  import w,x,y,z, ...
>
> If you have that list, you can do something like this instead of
> stealing the entire contents of the module:
>
> def init(param_module):
>     for name in ('w', 'x', 'y', 'z'):
>        globals()[name] = getattr(param_module, name)
>
> modules are just like any other object in this respect.
>
> p
> _________________________________________________
> Wing IDE users list
> http://wingware.com/lists/wingide



More information about the wingide-users mailing list