Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #34065
| Path | csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!ecngs!feeder2.ecngs.de!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <thbach@students.uni-mainz.de> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.015 |
| X-Spam-Evidence | '*H*': 0.97; '*S*': 0.00; 'cache': 0.05; '__name__': 0.07; 'responding': 0.07; '"if': 0.09; 'subject:files': 0.09; "'__main__':": 0.16; 'argparse': 0.16; 'csv': 0.16; 'iterating': 0.16; 'skip:n 50': 0.16; 'uppercase': 0.16; 'writer': 0.16; 'wrote:': 0.17; 'instance': 0.17; 'tests.': 0.17; 'thu,': 0.17; '(in': 0.18; '(not': 0.20; 'appropriate': 0.20; 'code.': 0.20; 'import': 0.21; 'own.': 0.22; 'insert': 0.23; 'statement': 0.23; 'header:In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'values': 0.26; '(e.g.': 0.27; 'subject:list': 0.28; '+0100,': 0.29; 'coded': 0.29; 'probably': 0.29; 'e.g.': 0.30; 'writes': 0.30; 'function': 0.30; 'figure': 0.30; 'file': 0.32; 'addresses': 0.32; 'structure': 0.32; 'says': 0.33; 'problem': 0.33; 'to:addr :python-list': 0.33; "can't": 0.34; 'list': 0.35; 'fresh': 0.35; 'nov': 0.35; 'open': 0.35; 'there': 0.35; 'list.': 0.35; 'add': 0.36; 'compare': 0.36; 'should': 0.36; 'does': 0.37; 'data': 0.37; 'subject:: ': 0.38; 'skip:l 20': 0.38; 'skip:o 20': 0.38; 'received:10': 0.38; 'several': 0.39; 'instead': 0.39; 'to:addr:python.org': 0.39; 'think': 0.40; 'your': 0.60; 'range': 0.60; 'content-disposition:inline': 0.60; 'places': 0.61; 'stand': 0.61; 'first': 0.61; 'letters': 0.62; 'strange': 0.62; 'thomas': 0.62; 'close': 0.63; 'improvements': 0.65; 'phone': 0.68; 'cut': 0.71; 'phones:': 0.84; 'received:10.94': 0.84 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=uni-mainz.de; i=@uni-mainz.de; q=dns/txt; s=ironport; t=1354190914; x=1385726914; h=date:from:to:subject:message-id:references:mime-version: content-transfer-encoding:in-reply-to; bh=L2ruKaSjaTl38Ly6lH6/6faSmQQzJoxslKFBJcCGblc=; b=ZPeQfuqrLfN/0HM6WLSEhVSYieJTZO9iQ1O6+Jp1xgNnN9AKIM5Js0D2 T5z8P+N6ur5ncgx952ZB3++eqk+p606k0anYE0DrcHU6zJujtqjdiDMob gXqXw64T+lGq/Pvhez+el2fjDTP0pp4lC8ji7ZYsN/Zce8RxmjJ7oQqoQ c=; |
| X-IronPort-Anti-Spam-Filtered | true |
| X-IronPort-Anti-Spam-Result | Ap8EAApPt1AKXgZY/2dsb2JhbABEhiu6DXOCHgEBBAEjDwFLCwsYAgImAgIUKQoWiB0GrFOCA4N1jG2BIosdgRqBehoyYQOWAAGQRIJzgiA |
| Date | Thu, 29 Nov 2012 13:07:34 +0100 |
| From | Thomas Bach <thbach@students.uni-mainz.de> |
| To | <python-list@python.org> |
| Subject | Re: Compare list entry from csv files |
| References | <CAKhY55M3iOhhMbn=VuwJ7OMz_JUHVxwGy1h_BDpfBY8jQ5aRkA@mail.gmail.com> <50B3E865.9070700@davea.name> <CAKhY55OUNvGFhCjZLS7HNoDydKqHxZrnaN+bWySCsmKSk1vqsw@mail.gmail.com> <50B43246.2010902@davea.name> <mailman.313.1354026304.29569.python-list@python.org> <ahk36lFeqmlU3@mid.individual.net> <mailman.320.1354042676.29569.python-list@python.org> <ahkmslFk897U1@mid.individual.net> <CAKhY55OdS7sHDpAg3kdnpqWH5yoORqzE0bTHJVgMWZSHqqZ4kQ@mail.gmail.com> |
| MIME-Version | 1.0 |
| Content-Type | text/plain; charset="utf-8" |
| Content-Disposition | inline |
| Content-Transfer-Encoding | 8bit |
| In-Reply-To | <CAKhY55OdS7sHDpAg3kdnpqWH5yoORqzE0bTHJVgMWZSHqqZ4kQ@mail.gmail.com> |
| User-Agent | Mutt/1.5.21 (2010-09-15) |
| X-Originating-IP | [146.60.14.25] |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.363.1354190916.29569.python-list@python.org> (permalink) |
| Lines | 63 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1354190916 news.xs4all.nl 6907 [2001:888:2000:d::a6]:50805 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:34065 |
Show key headers only | View raw
Can you please cut the message you are responding to the relevant
parts?
On Thu, Nov 29, 2012 at 11:22:28AM +0100, Anatoli Hristov wrote:
> The only problem I have is that I cant compare other field than the
> first one in
> for ex_phone in phones:
> telstr = ex_phone[0].lower()
> When I use telstr = ex_phone[0].lower() it says out of range and the
> strange think is that the range is 6 I can't figure that out.
As I understood it phones is an csv.reader instance and you are
iterating repeatedly over it. But, csv.reader does not work this
way. You either have to reinstantiate phones with a fresh
file-descriptor (not so good) or cache the values in an appropriate
data structure (better) e.g. a list.
> import csv
>
> # Open the file with the names and addresses
> origf = open('c:/Working/vpharma.csv', 'rt')
> # Open the file with the phone numbers
> secfile = open('c:/Working/navori.csv', 'rt')
Note that you never close origf and secfile.
> […]
> # Reads the file with the phone numbers
> # Format "First name","Lastname","Address","City","Country","Phone"
> phones = csv.reader(secfile, delimiter=';')
So this should probably be
PHONES = list(csv.reader(secfile, delimiter=';'))
(in uppercase letters as it is a global)
> […]
> if __name__ == '__main__':
> name_find()
>
> # Writes the list to a file
> wfile = open('c:/Working/ttest.csv', "wb")
> writer = csv.writer(wfile, delimiter=';')
> for insert in namelist:
> writer.writerow(insert)
> wfile.close()
This should go either in the "if __name__ = …" part or in a function
on its own.
Also have a look at the with statement you can use it in several
places of your code.
There are several other improvements you can make:
+ instead of having the file-names hard coded try to use argparse to
get them from the command-line,
+ let functions stand at their own and use less globals,
+ try to avoid the use of the type of the data structure in the name
(e.g. names is IMHO a better name then namelist),
+ add tests.
Regards,
Thomas
Back to comp.lang.python | Previous | Next — Previous in thread | 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