Python TypeError:未找到必需参数'source'(pos 1)

时间:2011-06-26 11:29:15

标签: python typeerror

我收到错误:TypeError: Required argument 'source' (pos 1) not found 但我不知道这意味着什么:/。谁能让我走上正轨? 我的代码是:

    def openFile(self,fileName):

    email_pattern = re.compile(r'\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b', re.IGNORECASE)

    with open(fileName) as lijstEmails: 
        self.FinalMailsArray.append([email_pattern.findall() for line in lijstEmails])
    self.writeToDB()

基本上它会在目录中打开一个数字文件,读取它们然后查找电子邮件地址并将它们写入数据库。

1 个答案:

答案 0 :(得分:10)

email_pattern.findall()需要传递参数。所以你的代码应该是这个 -

with open(fileName) as lijstEmails: 
    self.FinalMailsArray.append([email_pattern.findall(line) for line in lijstEmails])

请注意email_pattern.findall()会返回一个列表,因此您最终将列出的是列表。如果您确定每行包含最多1封email_address,则可以使用 -

with open(fileName) as lijstEmails: 
    self.FinalMailsArray.append([email_pattern.findall(line)[0] for line in lijstEmails])