开发者

Python TypeError: Required argument 'source' (pos 1) not found

I get an error: TypeError: Required argument 'source' (pos 1) not found but I haven't got a clue what it means :/. Can anyone put me on the right track? My code is:

    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()

Basical开发者_StackOverflowly it opens a number files in a directory, reads them and then goes looking for email addresses and writes them to a database.


email_pattern.findall() requires an argument to be passed. So your code should be this -

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

Note that email_pattern.findall() returns a list, so what you will be making will be list of list in the end. If you are sure that every line contains at the most 1 email_address then you can use -

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜