Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/23.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
';元组';对象没有属性';rstrip&x27;python_Python_Arrays_Input_Split_Int - Fatal编程技术网

';元组';对象没有属性';rstrip&x27;python

';元组';对象没有属性';rstrip&x27;python,python,arrays,input,split,int,Python,Arrays,Input,Split,Int,我正在编写一个python程序,该程序接收用户输入的int数组,该数组稍后进行排序。我已经在我的机器上成功编译了我的程序,但是,无法在Unix服务器上正确编译它。我机器上的Python编译器是版本3,而我相信服务器可能运行在Python 2.6上。我不确定根本问题是什么 list = input('Enter numbers in array with commas: ').rstrip() #this line is being flagged list = list.split(',') p

我正在编写一个python程序,该程序接收用户输入的int数组,该数组稍后进行排序。我已经在我的机器上成功编译了我的程序,但是,无法在Unix服务器上正确编译它。我机器上的Python编译器是版本3,而我相信服务器可能运行在Python 2.6上。我不确定根本问题是什么

list = input('Enter numbers in array with commas: ').rstrip() #this line is being flagged
list = list.split(',')
print(list)
我的错误:

 AttributeError: 'tuple' object has no attribute 'rstrip'

您正在使用Python2,其中
input()
相当于
eval(raw\u input())
。所以你实际上是在评估你的输入(我想是类似于
1,2
)是一个元组,它没有
rstrip
属性

使用
raw\u input
而不是
input
修复代码。这将为您提供一个字符串,您可以在上使用
rstrip


我还建议您使用另一个变量名来代替
list
,因为您将隐藏内置列表。

您使用的是Python2,其中
input()
相当于
eval(raw\u input())
。所以你实际上是在评估你的输入(我想是类似于
1,2
)是一个元组,它没有
rstrip
属性

使用
raw\u input
而不是
input
修复代码。这将为您提供一个字符串,您可以在上使用
rstrip

我还建议您使用另一个变量名来代替
list
,因为您将隐藏内置列表