Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 将长字符串分解为整数_Python_Python 2.7 - Fatal编程技术网

Python 将长字符串分解为整数

Python 将长字符串分解为整数,python,python-2.7,Python,Python 2.7,谢谢你仔细考虑我的问题 我是Python新手,所以我想在这里寻求您的帮助。我正在Win7上使用Python 2。我想把一个字符串分解成整数,这样我以后就可以比较int值了。我在谷歌上搜索了一些解决方案,但不起作用,请参阅下面的代码 angle = " 0 1 2 3 4 5 6 7 8 9 10 11" int_lst = [int(x) for x in angle] print int_lst 我收到了一个错误,回溯了上次的通话: ***File "C:/Users

谢谢你仔细考虑我的问题

我是Python新手,所以我想在这里寻求您的帮助。我正在Win7上使用Python 2。我想把一个字符串分解成整数,这样我以后就可以比较int值了。我在谷歌上搜索了一些解决方案,但不起作用,请参阅下面的代码

angle = " 0  1  2  3  4  5  6  7  8  9  10  11"
int_lst = [int(x) for x in angle]
print int_lst
我收到了一个错误,回溯了上次的通话:

 ***File "C:/Users/Desktop/pythonwifi/LDS Patern - Copy.py", line 2, in <module>
int_lst = [int(x) for x in angle]
ValueError: invalid literal for int() with base 10: ''"***

有什么建议吗?多谢各位

这一行是问题所在,因为它将迭代每个字符的角度字符串:

请尝试此操作,将空格上的角度字符串拆分为相关部分:

int_lst = [int(x) for x in angle.split()]

这一行是问题所在,因为它将迭代每个字符的角度字符串:

请尝试此操作,将空格上的角度字符串拆分为相关部分:

int_lst = [int(x) for x in angle.split()]

mapint,angle.split mapint,angle.split Hi@wim,有没有办法从结果中删除“[”和“]”?如中所示,我想将结果保存到csv文件中,csv文件中的当前外观是:|[0 | 1 | 2 |…| 11]| Hi@wim,是否有方法从结果中删除“[”和“]”?如中所示,我想将结果保存到csv文件中,csv文件中的当前外观为:|[0 | 1 | 2 |……| 11]|