python转换为int型错误

long552900806 2012-07-05 02:57:47
choicetime0=choice_3+choice_4
print choicetime0
choice_time=int(choicetime0)




Traceback (most recent call last):
File "D:\程序\python\ionogram_measure.py", line 826, in OnFindMe
choice_time1=int(choicetime01)
ValueError: invalid literal for int() with base 10: ''

print choicetime0 输出的是0300,然后一转换就报上面的错了
...全文
7296 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
long552900806 2012-07-05
  • 打赏
  • 举报
回复
我明白了,谢谢您
long552900806 2012-07-05
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 的回复:]
引用楼主 的回复:
Traceback (most recent call last):
File "D:\程序\python\ionogram_measure.py", line 826, in OnFindMe
choice_time1=int(choicetime01)
ValueError: invalid literal for int() with base 10: ''

……
[/Quote]
如果是空的怎么会输出u300呢
bugs2k 2012-07-05
  • 打赏
  • 举报
回复
[Quote=引用楼主 的回复:]
Traceback (most recent call last):
File "D:\程序\python\ionogram_measure.py", line 826, in OnFindMe
choice_time1=int(choicetime01)
ValueError: invalid literal for int() with base 10: ''
[/Quote]

说明你的int函数参数为空字符串,而不是你上面说的

>>> c = ''
>>> i = int(c)
Traceback (most recent call last):
File "<pyshell#26>", line 1, in <module>
i = int(c)
ValueError: invalid literal for int() with base 10: ''
>>>
bugs2k 2012-07-05
  • 打赏
  • 举报
回复
>>> c = 'abc'
>>> i = int(c)
Traceback (most recent call last):
File "<pyshell#18>", line 1, in <module>
i = int(c)
ValueError: invalid literal for int() with base 10: 'abc'
>>> c = u'0300'
>>> i = int(c)
>>> c,i
(u'0300', 300)
>>>
long552900806 2012-07-05
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 的回复:]
Python code

这个是多少呢:
print repr(choicetime0)
[/Quote]
u'0300' ,呵呵,这怎么弄啊
long552900806 2012-07-05
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 的回复:]
Python code

这个是多少呢:
print repr(choicetime0)
[/Quote]
u'0300',呵呵怎么弄啊
angel_su 2012-07-05
  • 打赏
  • 举报
回复
print repr(choicetime01)看看字符串的实际内容...
bugs2k 2012-07-05
  • 打赏
  • 举报
回复
这个是多少呢:
print repr(choicetime0)

37,720

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • IT.BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧