> On Mon, Jul 26, 2010 at 4:25 PM, Chris Rebert <c...@rebertia.com> wrote: >> On Mon, Jul 26, 2010 at 3:25 AM, lee <san82m...@gmail.com> wrote: >> > Hi, >> > >> > I have a value, >> > >> > partintid = int(Screw plugg (91_10 -> untitled)) >> > >> > but i get ValueError: invalid literal for int(): Screw plugg (91_10 - >> >> untitled) >> > any help? <snip> >> 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]: http://docs.python.org/library/stdtypes.html#string-methods
On Mon, Jul 26, 2010 at 4:03 AM, Sunny chilgod <san82m...@gmail.com> wrote: > Hi Chris, > Thanks for your help. but i need to to convert the whole string to int. > heres my full code, > ptid = 'item_01bom' > so item_01bom is a field name in form, so i get its value, > partintid = int(form[ptid]). # the value of form[ptid] is 'Screw plugg > (91_10 - untitled)' > Hence i get the error. hope i am clear now. Nope, still vague. Which is your desired value for partintid: 91? 10? 9110? "91_10"? Something else? Also, not to be unfriendly, but just note for future reference that top-posting ( http://en.wikipedia.org/wiki/Top-posting ) is generally avoided on this mailinglist/newsgroup. Cheers, Chris -- http://blog.rebertia.com -- http://mail.python.org/mailman/listinfo/python-list