[wingide-users] global imports
georgex.mclam at intel.com
Wed Jun 8 15:32:32 MDT 2011
> how does subroutine currently know how to use the project modules?
from project_conn import *
from project_eset import *
from project_parm import *
> 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.
When the code was originally written, everything was in one huge file.
You know, that works very well. Not much importing going on and everyone knows
When the second project/test came along, it was clear that much of the original
code could be re-used, but not all of it. In other languages the thing most
programmers do is to break out the common subroutines and manage them separately
(usually in a separate file). Now two projects/tests share 3 files. Ok.
Of course the above is a simplistic view of what is really going on. And yes there
are lots of different ways to accomplish the same thing. I have not heard one yet
that is better than the approach I have already taken; especially without major
changes to existing code.
The issue is getting subroutines to know the objects of the project/test of the
moment. So much for re-using the same code if the best solution is dozens of
copies of the same file (with changes only to import statements at the top)
From: wingide-users-bounces at wingware.com [mailto:wingide-users-bounces at wingware.com] On Behalf Of Adi J. Sieker
Sent: Wednesday, June 08, 2011 2:08 PM
To: wingide-users at wingware.com
Subject: Re: [wingide-users] global imports
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
>> 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.
> -----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:
>> Hmmm.... so a, b& c are the names of modules that I want to "import",
>> 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.
> Wing IDE users list
Wing IDE users list
More information about the wingide-users