一个高清功能我有一段代码运行正常,当我我的代码是不是在高清功能,而不是缩进我的代码工作。缩进时,这是我的代码。时不缩进,而不是在蟒蛇
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