我必须:
- 要求用户输入文件
- 检查文件是否存在
- 将数字(来自文件)存储在列表中
- 查找列表的长度
- 并在没有内置函数的情况下按降序排序
这是我到目前为止所拥有的:
def main():
try:
file=open(input (str("Please enter the name of the file you wish to open:" )),"r")
A= file.readlines()
print (A)
file.close
n=len(str(A))
print (n)
new_list=[]
for i in range (n):
for j in range (n-i):
if A(j-1) < A(j):
swap (A(j), A(j-1))
except IOError as e:
print("({})".format(e))
我不知道交换后要打印什么。我收到错误(“文件“C:/Python33/project.py”,第 15 行,如果 A(j-1) < A(j): TypeError: 'list' object is not callable")
我应该怎么办?