开发者

Converting string to integer with python

开发者 https://www.devze.com 2023-02-25 02:33 出处:网络
When trying to convert a string into integer to be used as a variable later in the code, I get the following:

When trying to convert a string into integer to be used as a variable later in the code, I get the following:

print int(urlsuccessful[i])

ValueError: invalid literal for int() with base 10: '2,919,24开发者_Go百科7'


locale.atoi() will "demark" integers based on the current locale setting.


If only problems are commas, try:

>>> int("2,919,247".replace(",", ""))
2919247


int does not understand commas, you'll want to remove those before trying to convert


You can just do

def int2str(my_integer):
  return "%d" % my_integer
0

精彩评论

暂无评论...
验证码 换一张
取 消