Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

module global variables

0 views
Skip to first unread message

pistacchio

unread,
May 12, 2008, 3:17:48 AM5/12/08
to
hi to all!
can i load a module passing to it, automatically and as default, all
the caller's global variables to act as module's global variables?
thanks

alex23

unread,
May 12, 2008, 4:01:47 AM5/12/08
to

module = __import__('module', globals=globals())

I think that's what you're looking for.

- alex23

pistacchio

unread,
May 12, 2008, 4:10:00 AM5/12/08
to


hmm, well, maybe yes.. should i ovveride the standard import function
of the module?
say that the module is called "pycatrix", would adding this to the
module solve the problem?

def __import__('pycatrix', globals=globals()):

pistacchio

unread,
May 12, 2008, 4:10:33 AM5/12/08
to

pardon, this:


def __import__('pycatrix', globals=globals()):

pass

Marco Mariani

unread,
May 12, 2008, 4:47:49 AM5/12/08
to
pistacchio wrote:
> On 12 Mag, 10:01, alex23 <wuwe...@gmail.com> wrote:
>> On May 12, 5:17 pm, pistacchio <pistacc...@gmail.com> wrote:
>>
>>> hi to all!
>>> can i load a module passing to it, automatically and as default, all
>>> the caller's global variables to act as module's global variables?

Are you positively sure you need this?

Modifying imported modules is already quite fragile, but this.. it's
basically a reversed(import *)

It's quite messy. Where quite equals to "very"

pistacchio

unread,
May 12, 2008, 5:11:27 AM5/12/08
to

well, i'm writing a module called pycatrix. within the module i have
compile / exec statements in a functions that work on global
variables. ( exec compiledTemplate in globals() ).

now, i don't want to be forced (or force the end user) to import to
call the module's function with a compulsory "globals()" as argument.

pistacchio

unread,
May 13, 2008, 9:36:48 AM5/13/08
to
On 12 Mag, 11:11, pistacchio <pistacc...@gmail.com> wrote:
> On 12 Mag, 10:47, Marco Mariani <ma...@sferacarta.com> wrote:
>
> >pistacchiowrote:
> > > On 12 Mag, 10:01, alex23 <wuwe...@gmail.com> wrote:
> > >> On May 12, 5:17 pm,pistacchio<pistacc...@gmail.com> wrote:
>
> > >>> hi to all!
> > >>> can i load a module passing to it, automatically and as default, all
> > >>> the caller's global variables to act as module's global variables?
>
> > Are you positively sure you need this?
>
> > Modifying imported modules is already quite fragile, but this.. it's
> > basically a reversed(import *)
>
> > It's quite messy. Where quite equals to "very"
>
> well, i'm writing a module called pycatrix. within the module i have
> compile / exec statements in a functions that work on global
> variables. ( exec compiledTemplate in globals() ).
>
> now, i don't want to be forced (or force the end user) to import to
> call the module's function with a compulsory "globals()" as argument.

up

0 new messages