Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #66777

Re:The sum of numbers in a line from a file

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.032
X-Spam-Evidence '*H*': 0.94; '*S*': 0.00; 'subject:file': 0.07; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'wrote': 0.14; 'columns': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'skip:d 60': 0.16; "i've": 0.25; 'this:': 0.26; 'header:X-Complaints-To:1': 0.27; 'subject:numbers': 0.31; 'file': 0.32; 'subject:from': 0.34; 'add': 0.35; 'two': 0.37; 'skip:o 20': 0.38; 'to:addr:python- list': 0.38; 'that,': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'name': 0.63; 'subject:The': 0.64; 'sample': 0.67; '100': 0.79; 'subject::': 0.85; 'average': 0.93
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Dave Angel <davea@davea.name>
Subject Re:The sum of numbers in a line from a file
Date Thu, 20 Feb 2014 11:54:09 -0500 (EST)
Organization news.gmane.org
References <882091da-a499-477e-8f50-c5bdde7cdfec@googlegroups.com>
X-Gmane-NNTP-Posting-Host wsip-68-106-144-188.dc.dc.cox.net
X-Newsreader PiaoHong Usenet NewsReaders 1.36
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 <https://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 <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.7199.1392915307.18130.python-list@python.org> (permalink)
Lines 22
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1392915307 news.xs4all.nl 2915 [2001:888:2000:d::a6]:35163
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:66777

Show key headers only | View raw


 kxjakkk <kjakupak@gmail.com> Wrote in message:
> Let's say I have a sample file like this:
> 
> Name        1           2     3    4     5      6     7    8
> ------------------------------------------------------------------------
> name1    099-66-7871   A-F    Y    100    67    81    59    98
> name2    999-88-7766   A-F    N    99   100    96    91    90
> name3    000-00-0110    AUD        5    100    28    19    76
> name4    398-72-3333    P/F    Y    76    84    49    69    78
> name5    909-37-3689    A-F    Y    97    94    100    61    79
> 
> For name1, I want to add together columns 4, 5, 6, and get an average from that, then do the same for the last two columns. I want to do this for every name. 
> 
> All I've got is
> sum([int(s.strip()) for s in open('file').readlines()])
> 

Don'ttrytodoitallinoneline.thatwayyouactuallymighthaveaplacetoinse
rtsomeextralogic.
-- 
DaveA

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

The sum of numbers in a line from a file kxjakkk <kjakupak@gmail.com> - 2014-02-20 08:22 -0800
  Re: The sum of numbers in a line from a file John Gordon <gordon@panix.com> - 2014-02-20 16:46 +0000
    Re: The sum of numbers in a line from a file kjakupak@gmail.com - 2014-02-20 10:16 -0800
      Re: The sum of numbers in a line from a file Joel Goldstick <joel.goldstick@gmail.com> - 2014-02-20 13:32 -0500
        Re: The sum of numbers in a line from a file kjakupak@gmail.com - 2014-02-20 10:37 -0800
          Re: The sum of numbers in a line from a file Peter Otten <__peter__@web.de> - 2014-02-20 19:59 +0100
      Re: The sum of numbers in a line from a file Chris “Kwpolska” Warrick <kwpolska@gmail.com> - 2014-02-20 19:56 +0100
      Re: The sum of numbers in a line from a file MRAB <python@mrabarnett.plus.com> - 2014-02-20 19:17 +0000
  Re:The sum of numbers in a line from a file Dave Angel <davea@davea.name> - 2014-02-20 11:54 -0500
  Re: The sum of numbers in a line from a file Travis Griggs <travisgriggs@gmail.com> - 2014-02-20 14:35 -0800
  Re: The sum of numbers in a line from a file Johannes Schneider <johannes.schneider@galileo-press.de> - 2014-02-21 09:16 +0100
  Re: The sum of numbers in a line from a file sffjunkie@gmail.com - 2014-02-24 03:48 -0800
    Re: The sum of numbers in a line from a file sffjunkie@gmail.com - 2014-02-24 04:02 -0800

csiph-web