Getting name from the email address in python
Question:
I have a text file in which there are email addresses in the following format:
[email protected]
or
some_name@somehost
How can I split the string to get some & name? I tried the following code, but it appears I can only use one character (just the @ or just the .).Is there a way to do it in one statement? Thanks.
name = email.split('@', '.')
Answers:
Use the following:
email = "[email protected]"
name, _, _ = email.partition("@") # returns before @, @, and after @
splitname = name.split(".") # splits on .
print(splitname)
["some", "name"]
In case of email addresses with no predefined structure, you can use: https://github.com/intuit/email-decomposer.
I have a text file in which there are email addresses in the following format:
[email protected]
or
some_name@somehost
How can I split the string to get some & name? I tried the following code, but it appears I can only use one character (just the @ or just the .).Is there a way to do it in one statement? Thanks.
name = email.split('@', '.')
Use the following:
email = "[email protected]"
name, _, _ = email.partition("@") # returns before @, @, and after @
splitname = name.split(".") # splits on .
print(splitname)
["some", "name"]
In case of email addresses with no predefined structure, you can use: https://github.com/intuit/email-decomposer.