【发布时间】:2014-03-27 15:39:08
【问题描述】:
尝试在 Python 中将好友 ID“5”转换为数字
当我尝试将此字符串转换为数字时出现错误:
[Applications/MAMP/htdocs/WhoAt/env/www/www/views/contacts/contacts.py line:63]
un_friend()
->contact = int(friend)
ValueError: invalid literal for int() with base 10: '"5"'
Python
## friend is "5" str
friend = self.request.body
## Tried:
contact = int(friend)
## and just:
int(friend)
我在here 和here 上面找到了我尝试过的代码。两者都不起作用,都导致上述错误。
你知道我做错了什么吗?我不想创建一个新的 def 只是为了转换它,有没有办法用几个字符来做到这一点?
【问题讨论】:
标签: python string integer pyramid