Created
October 7, 2016 16:42
-
-
Save anonymous/8cadf1b238f5dfea2e29133cb3026670 to your computer and use it in GitHub Desktop.
Python function to read a list of contacts from a given file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Function to read the contacts from a given contact file and return a | |
# list of names and email addresses | |
def get_contacts(filename): | |
names = [] | |
emails = [] | |
with open(filename, mode='r', encoding='utf-8') as contacts_file: | |
for a_contact in contacts_file: | |
names.append(a_contact.split()[0]) | |
emails.append(a_contact.split()[1]) | |
return names, emails |
I got an index error: list index out of range in line: names.append(a_contact.split()[0]). A half month ago, when I tried it first time, it was successfully executed, but after a period of time, I got an error above
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Traceback (most recent call last):
File "C:/Users/Lenovo/Desktop/Mailing.py", line 43, in
for name, email in zip(names, emails):
NameError: name 'names' is not defined
I am getting this error. Can some please help?