';元组';对象没有属性';rstrip&x27;python
我正在编写一个python程序,该程序接收用户输入的int数组,该数组稍后进行排序。我已经在我的机器上成功编译了我的程序,但是,无法在Unix服务器上正确编译它。我机器上的Python编译器是版本3,而我相信服务器可能运行在Python 2.6上。我不确定根本问题是什么';元组';对象没有属性';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
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
,因为您将隐藏内置列表