with 문에 구문 오류가 있습니다. 나는 그것을 이해할 수 없다. 나는 파이썬 3을 사용하고 있으며 매번 문장을 사용할 때마다 그냥 사용하지 않을 것이다. 나는 txt 파일을위한 독자를 만들려고하고 있는데, 나는 이것을 성명서와 함께 필요로한다.python 3.0 "with"구문 오류가 있습니까?
import csv
value1 = "Spam"
fname = input(open("Please enter the name of the file you wish to open: ")
with open(fname, 'rb') as csvfile:
spamreader = csv.reader(csvfile, delimiter=' ', quotechar='|')
for row in spamreader:
if value1 in row:
print(" ".join(row))
내가 도움을들
을 제외 : 파이썬 3에서 csv 파일을 열기하는 경우, 당신은'개방 사용해야합니다 (FNAME, 'R'을, 줄 바꿈 = '') '대신'open (fname, 'rb')'(이것은 파이썬 2에서 어떻게 사용했는지를 보여줍니다.) [docs] (http://docs.python.org/3/library/csv.html#examples). – DSM