【发布时间】:2019-02-02 18:52:52
【问题描述】:
我正在尝试使用特定参数清理文本文档。尝试了x=... 行的不同迭代,但程序无法读取所有行。
import re
#import csv
text = open(r'C:\Users\Vincent\Documents\python\theSortingHat\100000DirtyNames.txt') #open text file
for line in text: #iterate through every line
#return list of names in that line
x = re.findall ('^([a-zA-Z]-?$')
#if an actual name is found
if x != 0:
print(x)
我收到:
错误:类型错误:findall() 缺少 1 个必需的位置参数: '字符串'
【问题讨论】:
-
您没有使用包含要搜索正则表达式的文本的
linevariable。提问前请参考re或re.findall的文档。
标签: regex python-3.x