Converting String to int
Ognjen Bezanov
ognjen at mailshack.com
Sun May 14 16:23:52 EDT 2006
Hi all, Another problem, with the same error (error: "invalid literal for
int()")
code:
mynums = "423.523.674.324.342.122.943.421.762.158.830"
mynumArray = string.split(mynums,".")
x = 0
for nums in mynumArray:
if nums.isalnum() == true:
x = x + int(nums)
else:
print "Error, element contains some non-numeric characters"
break
/end code
This seemed like a simple thing, and I have done it before with no issues.
have I missed something obvious? taking into account my previous hex
question, I tried changing int(nums) to int(nums,10) but it still gives me
the error
More information about the Python-list
mailing list