问题描述
并非所有行都从我的 CSV 文件中打印出来,它只打印第一行并再次返回到 while
循环。我想在打印所有行之后添加另一个函数,但由于某种原因它不起作用。
import csv
import pandas as pd
import stdiomask
def volleyball_court():
print("Volleyball Courts")
print()
with open("location.csv","r") as csvfile:
csvreader = csv.reader(csvfile,delimiter=',')
location = (input("Enter your suburbs:")
for row in csvreader:
if location in str(row[0]):
print(row)
return_menu()
解决方法
您在 if 语句中调用 return_menu() ,将其移出 for 循环,您应该没问题。
for row in csvreader:
if location in str(row[0]):
print(row)
return_menu()