我想我是一个使用python3.3的初学者。 我试着编写一个简单的程序,询问用户想要搜索什么,比如电影或者电影中的主角(所有的电影细节都会显示出来)
我写了以下代码:
def displayuserinfo():
from collections import namedtuple
import csv
global file
file=namedtuple('file', 'movie, starring, comments, year')
global records
records=[""]*300
global addressbook
addressbook= open(r"C:\Users\Desktop\filmscsv.csv", "r")
global counter
counter=0
for line in addressbook:
records[coounter] = file._make(line)
records = records + 1
def movie():
global movie
global moviecounter
found= False
movie= input("Enter the movie:")
movie= movie.lower()
moviecounter=0
def movie_validation():
moviecounter=0
for i in range(counter):
if records[i].movie[:]== movie:
print(records[i].movie)
moviecounter += 1
def starring():
global starring
global starringcounter
found= False
starring= input("Enter who's starring:")
starring= starring.lower()
starringcounter=0
def starring_validation():
starringcounter=0
for i in range(counter):
if records[i].starring[:]== starring:
print(records[i].starring)
starringcounter += 1
#main
global choice
choice= str(input("What do you wish to do: 1. 2. 3.:"))
found= False
while found is not True:
if choice== "0":
print("Goodbye!")
elif choice == "1":
displayuserinfo()
movie()
movie_validation()
found= True
elif choice== "2":
displayuserinfo()
starring()
starring_validation()
found = True
else:
print("Incorrect choice!")
choice= input("What do you wish to do?:")
每次运行代码时都会出现此错误: SyntaxError:(unicode错误)“UnicodeScape”编解码器无法解码位置2-3中的字节:截断\uxxxxxxxxx转义
我很长时间以来一直在努力制定这个计划。我也得用几年的时间来做,但那是另一回事。 我只是想让它工作,我知道文件是正确的,但我就是看不出问题在哪里。也许是因为我没有程序员的头脑。 有谁能建议一下怎么做吗? 感谢任何有用的评论。 P、 很抱歉代码没有显示为代码,但我是新来的网站,还没有想出如何做到这一点。在
这是因为您使用了
\
s,这是Python中的转义字符。尝试:相反。在
相关问题 更多 >
编程相关推荐