到目前为止,我已经得到了这个代码。您输入一个数字,它应该读取文件中的特定行packages.txt
并将其打印到 python shell。在下面的代码中,例如,如果您输入“3”,它将打印我不希望的第 1-3 行做。
which = input('Which package would you like?: ')
with open('packages.txt') as f:
i = 0
for line in f:
if i == (int(which)):
break
i += 1
print (line)