user variables
Michele Simionato
mis6 at pitt.edu
Wed Jun 25 08:52:45 EDT 2003
user at domain.invalid wrote in message news:<3EF81F8C.9070103 at domain.invalid>...
> Sorry this must be really trivial, but I am new to Python...
> suppose I defined
> a=5
> b=7
> c=9
>
> is there a command like
>
> usr_vars()
>
> which would show
>
> a=5
> b=7
> c=9
>
> ????
>
> I tried globals(), locals() and vars(), but they all mix my user-defined
> variables with system ones... clues? ideas?
>
> thanks in advance,
>
> Pier
Dunno if there is a better way, but brute force works:
systemvars=globals().copy()
systemvars['systemvars']=systemvars
systemvars['_[1]']=None # comment this and you will discover something
a=5
b=7
c=9
uservars=dict([slot for slot in globals().items()
if not slot[0] in systemvars])
print uservars
# => {'a': 5, 'c': 9, 'b': 7}
HTH,
Michele
More information about the Python-list
mailing list