Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #45769
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <carlosnepomuceno@outlook.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.036 |
| X-Spam-Evidence | '*H*': 0.93; '*S*': 0.01; 'skip:[ 20': 0.04; 'column': 0.07; 'subject:file': 0.07; 'filenames': 0.09; '###': 0.16; '6th': 0.16; 'csv': 0.16; 'separated': 0.16; 'subject:arithmetic': 0.16; "skip:' 30": 0.19; 'to:name:python- list@python.org': 0.22; 'print': 0.22; 'received:65.55.116': 0.24; 'skip:{ 20': 0.24; 'subject:/': 0.26; 'values': 0.27; 'header:In- Reply-To:1': 0.27; 'lines': 0.31; "skip:' 10": 0.31; 'piece': 0.31; 'file': 0.32; 'skip:o 20': 0.38; 'to:addr:python-list': 0.38; 'files': 0.38; 'to:addr:python.org': 0.39; '8bit%:6': 0.40; '5th': 0.60; 'such': 0.63; '1st': 0.74; 'as:': 0.81; '8bit%:24': 0.84; 'improved.': 0.84; '8bit%:18': 0.93; 'average': 0.93 |
| X-TMN | [cY9LPUhQwKYVSVPgMI2HoszvcaLn36Ki] |
| X-Originating-Email | [carlosnepomuceno@outlook.com] |
| From | Carlos Nepomuceno <carlosnepomuceno@outlook.com> |
| To | "python-list@python.org" <python-list@python.org> |
| Subject | RE: file I/O and arithmetic calculation |
| Date | Thu, 23 May 2013 06:15:58 +0300 |
| Importance | Normal |
| In-Reply-To | <BLU176-W45829351ABC75D63C63DC9D7AA0@phx.gbl> |
| References | <BLU176-W45829351ABC75D63C63DC9D7AA0@phx.gbl> |
| Content-Type | text/plain; charset="iso-8859-1" |
| Content-Transfer-Encoding | quoted-printable |
| MIME-Version | 1.0 |
| X-OriginalArrivalTime | 23 May 2013 03:15:58.0818 (UTC) FILETIME=[D8A1BC20:01CE5763] |
| 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.1988.1369278966.3114.python-list@python.org> (permalink) |
| Lines | 25 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1369278966 news.xs4all.nl 15929 [2001:888:2000:d::a6]:50646 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:45769 |
Show key headers only | View raw
The last line of my noob piece can be improved. So this is it:
### 1strow_average.py ###
#Assuming you have CSV (comma separated values) files such as:
#1.txt = '0,1,2,3,4,5,6,7,8,9\n' \
# '10,11,12,13,14,15,16,17,18,19\n' \
# '20,21,22,23,24,25,26,27,28,29\n' ...
#
# Usage: contents[file][row][column]
# contents[0] : file '1.txt'
# contents[1][2] : 3rd row of file '2.txt'
# contents[3][4][5] : value on the 6th column of 5th row of file '4.txt'
# len(contents) : quantity of files
# len(contents[4]) : quantity of lines in file '5.txt'
# len(contents[4][0]: quantity of values in the 1st line of file '5.txt'
filenames = ['1.txt', '2.txt', '3.txt', '4.txt', '5.txt']
contents = [[[int(z) for z in y.split(',')] for y in open(x).read().split()] for x in filenames]
s1c = [sum([r[0] for r in f]) for f in contents]
a1r = [sum(f[0])/float(len(f[0])) for f in contents]
print '\n'.join(['File "{}" has 1st row average = {:.2f}'.format(n,a1r[i]) for i,n in enumerate(filenames) if s1c[i]==50])
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
RE: file I/O and arithmetic calculation Carlos Nepomuceno <carlosnepomuceno@outlook.com> - 2013-05-23 06:15 +0300
csiph-web