과제는 파일을 열고 텍스트 파일을 열고 사용 된 모든 단어의 목록을 만드는 것입니다. 파일을 열거 나 읽고 닫을 수는 있지만 분할하려고하면 아래 오류가 발생합니다.Python 3에서 텍스트를 분할하는 방법
이것은 무엇을 의미하며 어떤 제안이 있습니까?
file = open("decl.txt", "r")
lines = file.readlines()
text.close()
# split oliver
words = re.split('\W+', lines)
print(words)
Traceback (most recent call last):
File "lab.py", line 18, in <module>
words = re.split('\W+', lines)
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/re.py", line 165, in split
TypeError: expected string or buffer
왜 텍스트를 닫는? 그게 파일이 될까요? – thefourtheye