Skip to content

Instantly share code, notes, and snippets.

@burritoOverflow
Created March 22, 2020 21:42
Show Gist options
  • Save burritoOverflow/0fc74367d9a2d045a1fb34b80f5ddfb3 to your computer and use it in GitHub Desktop.
Save burritoOverflow/0fc74367d9a2d045a1fb34b80f5ddfb3 to your computer and use it in GitHub Desktop.
import csv
import sys
if len(sys.argv) is not 2:
print("Filename argument required")
exit(1)
else:
customers_dict = dict()
with open(sys.argv[1], 'r', newline='') as csv_file:
# skip the first line
next(csv_file)
csv_reader = csv.reader(csv_file, delimiter=',')
for row in csv_reader:
# make email the key for the dict
customers_dict[row[0]] = dict(
name = f"{row[2]}, {row[1]}",
fullname = row[3],
position = row[4],
department = row[5],
# just choose one of them here for simplicity
phone = row[7],
address = f"{row[10]}, {row[11]}, {row[12]} {row[13]}"
)
print(customers_dict)
User Name First Name Last Name Display Name Job Title Department Office Number Office Phone Mobile Phone Fax Address City State or Province ZIP or Postal Code Country or Region
[email protected] Chris Green Chris Green IT Manager Information Technology 123451 123-555-1211 123-555-6641 123-555-9821 1 Microsoft way Redmond Wa 98052 United States
[email protected] Ben Andrews Ben Andrews IT Manager Information Technology 123452 123-555-1212 123-555-6642 123-555-9822 1 Microsoft way Redmond Wa 98052 United States
[email protected] David Longmuir David Longmuir IT Manager Information Technology 123453 123-555-1213 123-555-6643 123-555-9823 1 Microsoft way Redmond Wa 98052 United States
[email protected] Cynthia Carey Cynthia Carey IT Manager Information Technology 123454 123-555-1214 123-555-6644 123-555-9824 1 Microsoft way Redmond Wa 98052 United States
[email protected] Melissa MacBeth Melissa MacBeth IT Manager Information Technology 123455 123-555-1215 123-555-6645 123-555-9825 1 Microsoft way Redmond Wa 98052 United States
@burritoOverflow
Copy link
Author

csv reader example using a microsoft provided csv

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment