[Tutor] int("10**6")
Albert-Jan Roskam
fomcl at yahoo.com
Wed Aug 1 10:37:00 CEST 2012
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?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20120801/20cf811f/attachment.html>
More information about the Tutor
mailing list