一個高清功能我有一段代碼運行正常,當我我的代碼是不是在高清功能,而不是縮進我的代碼工作。縮進時,這是我的代碼。時不縮進,而不是在蟒蛇
import csv
my_file = open("marqueeTables.csv", "r")
search_data = input("Please enter the data you are looking for")
search_data = (search_data + " metre wide")
#print(search_data)
reader = csv.reader(my_file)
for row in my_file:
if search_data in str(row): # == "6 metre wide":
stripedRow = row.strip()
splitStrippedRow = stripedRow.split(",")[0]
print(splitStrippedRow)
#print(row)
It prints "6 metre wide" or "12 metre wide" depending on whether I type 6 or 12.
下面是類似的代碼,但在高清(只有幾件事情已經改變):
def userInfo():
while True:
w = str(input("What size width marque would you like 6 or 12: "))
if w == "6":
myFile = open("userDetails.csv", "a+")
myFile.write(str(w) + ", ")
myFile.close()
break
elif w == "12":
myFile = open("userDetails.csv", "a+")
myFile.write(str(w) + ", ")
myFile.close()
break
else:
print("Pleas type 6 or 12")
w = (w + "metre wide")
my_file = open("marqueeTables.csv", "r")
#search_data = input("Please enter the data you are looking for")
reader = csv.reader(my_file)
for row in my_file:
if w in str(row):
stripedRow = row.strip()
splitStrippedRow = stripedRow.split(",")[0]
print(splitStrippedRow)
userInfo()
當我運行的代碼,它打印「6.米寬的」和「座位數」和「十二米寬的」和「座位」了(因爲它是表中的兩倍。)
有人能告訴我爲什麼我的代碼是不是在蟒蛇感謝工作將是巨大的。我正在使用python 3.5。由於
你是什麼意思「不起作用」?請閱讀[mcve]。 –
在你的第二個代碼塊中,你不要調用函數'userInfo' ... – AlG
同樣在你的第二個代碼塊中'elif w ==「12」:'應該是縮進的。 – agold