我似乎無法在csv文件中找到輸入值,只顯示包含輸入值的行。 csv數據與打印標題的對齊也是我正在努力解決的一個問題。如何僅顯示包含輸入值的csv文件中的行,使用python進行對齊3.6.1
import csv
def menu():
print("Menu") #Prints menu page to select option
print("======")
print("[1]: Display info")
print("[0]: Exit")
def info():
read = csv.reader(open("value.csv", "r"))
for j in read:
print(j[:4])
while True:
menu()
selection = int(input("Enter your selection: ")) #Choose selection from menu
if selection == 1:
print("1: Display info")
print()
Num = str(input("Enter a value.: ")) #Input value to find for match, refers to the Value in value.csv file
print("{:<10}{:<15}{:<15}{:<11}".format("Value", "Time", "Distance", "Pace")) #Prints heading
print("{:<10}{:<15}{:<15}{:<11}".format("--------", "-------------", "-------------", "---------")) #Prints heading with alignment
info() #Executes def function
elif selection == 0:
break #Exit from program
您如何期待它的工作?你甚至不會把'Num'傳遞給'info'。 –