pythonic equivalent of upvar?
Steven D'Aprano
steve at REMOVETHIScyber.com.au
Tue Dec 20 16:58:52 EST 2005
On Tue, 20 Dec 2005 14:56:25 +0000, Richie Hindle wrote:
>
> [David]
>> I'm trying to write something with the same brevity
>> as perl's one-liner
>>
>> eval "\$$1=\$2" while @ARGV && $ARGV[0]=~ /^(\w+)=(.*)/ && shift;
>
> import sys, re
> for arg in sys.argv[1:]:
> if re.match(r'\w+=.*', arg):
> exec arg
> else:
> break
That piece of code is quite dangerous, since it is calling exec on an
arbitrary string supplied by a user.
--
Steven.
More information about the Python-list
mailing list