Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
Python
ValueError: invalid literal for int():
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="Chris Rebert, post: 4106699"] That is most certainly not your actual exact code, since it has a few SyntaxErrors and thus Python would have bailed-out long before it ever got the chance to raise ValueError. Please copy-and-paste the *actual exact code* and exact error message. Also, next time say what the desired output/behavior you're seeking is. That being said, if your code is (as I suspect) in actuality: partintid = int("Screw plugg  (91_10 -> untitled)") then I would agree with int() and say that that string is nowhere close to representing an integer (how precisely is "Screw" to be interpreted as an integer, pray tell?); so what's so surprising about getting an error when trying to convert it to one? I suspect you're trying to extract 91 or 10 from the string. Use string methods[1] to parse the desired numerical section out of the string, and then pass the resulting numerical string to int(), which will accept it without error and properly convert it. If you want more detailed help, please provide a specification of typical input strings and desired output integers. [1]: [URL]http://docs.python.org/library/stdtypes.html#string-methods[/URL] Regards, Chris [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
Python
ValueError: invalid literal for int():
Top