Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How to cast a string with an exponent from sys.argv to an Integer ?


For an exercise, I have written a Python script that takes an integer argument. Of course, the input in sys.argv is of type 'str', so I cast it to an Integer. It works, but I am supposed to accept numbers written like '123^1237' too, with a hat for the exponent. And I cannot find how to do that. In the sage interpreter, I can type "n = Integer(123^1237)" without any problem, but in my script it fails with a "TypeError: unable to convert '123^1237' to an integer". Thanks