Changing behaviour of namespaces - solved, I think

Mikael Olofsson mikael at isy.liu.se
Thu Sep 21 11:12:56 EDT 2006


Peter Otten wrote:
> Clearly more elegant than:
>
>   
>>>> print open(filename).read()
>>>>         
> b = a
>   
>>>> dummy = 42
>>>> names = []
>>>> while 1:
>>>>         
> ...     ns = dict((n, dummy) for n in names)
> ...     try:
> ...             execfile(filename, ns)
> ...     except NameError, e:
> ...             names.append(e[0][6:-16])
> ...     else:
> ...             break
> ...
>   
>>>> names
>>>>         
> ['a']
>   

That sure is nicer. My solution looks like shooting mosquitoes with an 
elephant rifle i comparison. Thanks.

/MiO



More information about the Python-list mailing list