Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
converting to int
#11
(Jul-24-2022, 10:41 PM)Skaperen Wrote: just a quick look at it doesn't show me how it would get the value 345 from the string "345foo99boo123" or the value 65533 from the string "0xfffdummyfff".
Sorry. I guess I misunderstood. Blush
Reply
#12
so, in the end, what i do is start with the full string and pass it to int() in arg 1 while passing 0 in arg 2. this is done under try:. if there is an exception (expecting ValueError) then shorten the string by one character removed from the end until either the string is exhausted, or a success is reached. if success, return that value. if not, raise ValueError.
rob101 likes this post
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020