Hi 
I want the user to be able to specify "10**6" as arguments. How can I cast this 
string value (it's from sys.argv) to an int value?.
Simply doing int("10**6") won't work. The code below works, but seems overly 
complicated.
 
import re
POW = lambda x, y=1: pow(x, y)
convert = lambda n: POW(*map(int, re.split(r"[*]*", str(n))))
nrows, ncols = map(convert, (sys.argv[1], sys.argv[2])

Any ideas how to improve this?

Regards,
Albert-Jan


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
All right, but apart from the sanitation, the medicine, education, wine, public 
order, irrigation, roads, a 
fresh water system, and public health, what have the Romans ever done for us?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to