Compare list entry from csv files

Discussion in 'Python' started by Anatoli Hristov, Nov 26, 2012.

  1. Hello,

    I'm trying to complete a namebook CSV file with missing phone numbers
    which are in another CSV file.
    the namebook file is structured:
    First name;Lastname; Address; City; Country; Phone number, where the
    phone number is missing.

    The phonebook file is structured as:
    Name; phone, where the name shows first and last name and sometimes
    they are written together like "BillGates" or "Billgatesmicrosoft".

    I'm importing the files as lists ex.: phonelist" ["First name", "Last
    name","address","City"."Country","phone"],[etc...]
    in the loop I can compare the entry for ex. "Bill Gates" in the field
    "BillGatesmicrosoft" but I can't index it so I can only take the phone
    number from the file with the phones and insert it to field in the
    Namebook. Can you please give me an advice?

    Thanks


    import csv

    origf = open('c:/Working/Test_phonebook.csv', 'rt')
    phonelist = []

    try:
    reader = csv.reader(origf, delimiter=';')
    for row in reader:
    phonelist.append(row)
    finally:
    origf.close()

    secfile = open('c:/Working/phones.csv', 'rt')
    phones = []

    try:
    readersec = csv.reader(secfile, delimiter=';')
    for row in readersec:
    phones.append(row)
    finally:
    secfile.close()
    Anatoli Hristov, Nov 26, 2012
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Michal Mikolajczyk
    Replies:
    0
    Views:
    647
    Michal Mikolajczyk
    Feb 13, 2004
  2. Dave Angel

    Re: Compare list entry from csv files

    Dave Angel, Nov 26, 2012, in forum: Python
    Replies:
    0
    Views:
    245
    Dave Angel
    Nov 26, 2012
  3. Anatoli Hristov

    Re: Compare list entry from csv files

    Anatoli Hristov, Nov 26, 2012, in forum: Python
    Replies:
    0
    Views:
    232
    Anatoli Hristov
    Nov 26, 2012
  4. Emile van Sebille

    Re: Compare list entry from csv files

    Emile van Sebille, Nov 26, 2012, in forum: Python
    Replies:
    0
    Views:
    235
    Emile van Sebille
    Nov 26, 2012
  5. Anatoli Hristov

    Re: Compare list entry from csv files

    Anatoli Hristov, Nov 27, 2012, in forum: Python
    Replies:
    9
    Views:
    229
    Anatoli Hristov
    Nov 30, 2012
Loading...

Share This Page