AttributeError: 'tuple' object has no attribute 'readline'
引诱我Metadata file '.dll' could not be found
。
答案 0 :(得分:0)
coffee_file=('c:/test/coffee.txt','r')
行。你应该写coffee_file=open('c:/test/coffee.txt','r')
。我使用with
语句替换了上下文管理器。while
循环是无限的,所以我使用了for
循环。假设您要在文件中找到提升的字符串 - 此代码应该有效:
def main():
found = False
search = input("Enter a description to search :- ").rstrip()
with open('c:/test/coffee.txt') as coffee_file:
for line in coffee_file:
qty = line.rstrip()
if search == qty:
print("Description :- ", search)
print("Quantity :- ", qty)
found = True
if not found:
print("Description :- ", search)
print("Quantity :- not found")
main()
P.S。请在下次提供输入数据(在本例中为c:/test/coffee.txt
)样本和预期输出。