how to create a pointer, or is there a better solution ?

Diez B. Roggisch deets at nospam.web.de
Sat Oct 13 09:21:18 EDT 2007


stef mientki schrieb:
> hello,
> 
> I've a program where users can make modules,
> by just dumping them in a certain directory,
> then they will dynamically link into the program if needed.
> 
> One of the communication channels I use,
> is a general global file, which should be imported by all user modules.
> 
> One of the things a user should be able to do is to create " global 
> variables",
> which should then be available in all the other program modules.
> So the global file contains a list, call JAL_Globals = [],
> where each user can append the globals he want to be exposed to the 
> outside world (for read only).
> Now if these globals are complex items, no problem, I get pointers and 
> can access them.
> But if these variables are simple, like integers, I get the value only 
> once ;-)
> 
> How can I create of dynamic pointers, even to simple variables ?
> Or is there a better way ?

Don't use a list, use a dictionary that has names mapped to values. Then 
the problem goes away, because instead of mutating an object (which you 
still can do), you can also rebind a new one -e.g like this:


JAL_Globals['name'] += 100

Diez



More information about the Python-list mailing list