开发者

Converting string to integer with python

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜