Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #33970
| References | <CAKhY55M3iOhhMbn=VuwJ7OMz_JUHVxwGy1h_BDpfBY8jQ5aRkA@mail.gmail.com> <50B3E865.9070700@davea.name> <CAKhY55OUNvGFhCjZLS7HNoDydKqHxZrnaN+bWySCsmKSk1vqsw@mail.gmail.com> <50B43246.2010902@davea.name> |
|---|---|
| Date | 2012-11-27 15:24 +0100 |
| Subject | Re: Compare list entry from csv files |
| From | Anatoli Hristov <tolidtm@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.313.1354026304.29569.python-list@python.org> (permalink) |
On Tue, Nov 27, 2012 at 4:23 AM, Dave Angel <d@davea.name> wrote:
> On 11/26/2012 05:27 PM, Anatoli Hristov wrote:
>> I understand, but in my case I have for sure the field "Name" in the
>> second file that contains at least the first or the last name on it...
>> So probably it should be possible:)
>> The Name "Billgatesmicrosoft" contains the word "Gates" so logically I
>> might find a solution for it.
>>
>
> (Please don't top-post. Or if you must, then delete everything after
> your post, as I'm doing here. Otherwise you end up with insanities like
> new stuff, quote-4, quote-1, quote-3, quote-2. In this case, long
> tradition on this forum and many like it work well, even if Microsoft
> mail programs and some others decide to put the cursor at the wrong end
> of the existing text. In most programs, it's configurable.)
>
> If you can come up with an algorithm for comparing first+last in one
> file to name in the other, then the problem can be solved. But you
> can't do it by hand-waving, you have to actually figure out a mechanism.
> Then we can help you code such a thing. And I can just about guarantee
> that if these fields are created independently by human beings, that
> there will be exceptions that have to fixed by human beings.
>
>
> --
>
> DaveA
Thanks for your help. I will do my best for the forum :)
I advanced a little bit with the algorithm and at least I can now
extract and compare the fields :)
For my beginner skills I think this is too much for me. Now next step
is to add the second field with the number to the Namelist and copy it
to a third filename I suppose.
import csv
origf = open('c:/Working/Test_phonebook.csv', 'rt')
secfile = open('c:/Working/phones.csv', 'rt')
phonelist = []
namelist = []
names = csv.reader(origf, delimiter=';')
phones = csv.reader(secfile, delimiter=';')
for tel in phones:
phonelist.append(tel)
#print "*"*25,phonelist,"*"*25
rows = 0
def finder(name_row):
for ex_phone in phonelist:
# phonelist.append(tel)
telstr = ex_phone[0].lower()
# print "*"*25 + " I got %s" % telstr
# print "\nGot name from Name_Find :%s" % name_row
if telstr.find(name_row) >= 0:
print "\nName found: %s" % name_row
else:
pass
return
# print "\nNot found %s" % name_row
def name_find():
for row in names:
namelist.append(row)
name_row = row[0].lower()
# print "\nExtracted Name is :% s" % name_row
finder(name_row)
# name_find()
# rows = rows +1
name_find()
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll thread
Re: Compare list entry from csv files Anatoli Hristov <tolidtm@gmail.com> - 2012-11-27 15:24 +0100
Re: Compare list entry from csv files Neil Cerutti <neilc@norwich.edu> - 2012-11-27 15:05 +0000
Re: Compare list entry from csv files Anatoli Hristov <tolidtm@gmail.com> - 2012-11-27 19:57 +0100
Re: Compare list entry from csv files Neil Cerutti <neilc@norwich.edu> - 2012-11-27 20:41 +0000
Re: Compare list entry from csv files Anatoli Hristov <tolidtm@gmail.com> - 2012-11-29 11:22 +0100
Re: Compare list entry from csv files Thomas Bach <thbach@students.uni-mainz.de> - 2012-11-29 13:07 +0100
RE: Compare list entry from csv files "Prasad, Ramit" <ramit.prasad@jpmorgan.com> - 2012-11-29 23:13 +0000
Re: Compare list entry from csv files Dave Angel <d@davea.name> - 2012-11-29 22:17 -0500
Re: Compare list entry from csv files Anatoli Hristov <tolidtm@gmail.com> - 2012-11-30 10:26 +0100
Re: Compare list entry from csv files Anatoli Hristov <tolidtm@gmail.com> - 2012-11-30 10:29 +0100
Re: Compare list entry from csv files Dave Angel <d@davea.name> - 2012-11-27 14:59 -0500
csiph-web