Created
March 22, 2020 21:42
-
-
Save burritoOverflow/0fc74367d9a2d045a1fb34b80f5ddfb3 to your computer and use it in GitHub Desktop.
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
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) |
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
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 | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
chris@contoso.com | 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 | |
ben@contoso.com | 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 | |
david@contoso.com | 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 | |
cynthia@contoso.com | 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 | |
melissa@contoso.com | 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
csv reader example using a microsoft provided csv