Path: csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.028 X-Spam-Evidence: '*H*': 0.94; '*S*': 0.00; 'skip:[ 20': 0.04; 'column': 0.07; 'subject:file': 0.07; 'filenames': 0.09; 'rows': 0.09; 'python': 0.11; '###': 0.16; '6th': 0.16; 'assumptions': 0.16; 'columns': 0.16; 'csv': 0.16; 'files)': 0.16; 'need:': 0.16; 'received:65.55.116.7': 0.16; 'separated': 0.16; 'subject:arithmetic': 0.16; 'all,': 0.19; 'advance.': 0.19; "skip:' 30": 0.19; 'thu,': 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; 'url:mailman': 0.30; 'code': 0.31; 'lines': 0.31; "skip:' 10": 0.31; 'file': 0.32; 'text': 0.33; 'url:python': 0.33; 'date:': 0.34; 'could': 0.34; 'url:listinfo': 0.36; 'url:org': 0.36; 'requirements': 0.37; 'email addr:python.org': 0.37; 'skip:o 20': 0.38; 'thank': 0.38; 'follows:': 0.38; 'to:addr:python-list': 0.38; 'files': 0.38; 'skip:_ 30': 0.39; 'subject:': 0.39; 'to:addr:python.org': 0.39; '8bit%:6': 0.40; 'url:mail': 0.40; '5th': 0.60; 'simple': 0.61; 'first': 0.61; 'email addr:gmail.com': 0.63; 'such': 0.63; 'dear': 0.65; 'email name :python-list': 0.65; 'below:': 0.68; '1st': 0.74; 'as:': 0.81; '(10': 0.84; '+0900': 0.84; '8bit%:24': 0.84; '8bit%:18': 0.93; 'average': 0.93; '2013': 0.98 X-TMN: [VfL9gqDvWdyZI1SkQ6Sa38aMH3oIf4Fe] X-Originating-Email: [carlosnepomuceno@outlook.com] From: Carlos Nepomuceno To: "python-list@python.org" Subject: RE: file I/O and arithmetic calculation Date: Thu, 23 May 2013 00:05:15 +0300 Importance: Normal In-Reply-To: References: Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginalArrivalTime: 22 May 2013 21:05:15.0995 (UTC) FILETIME=[0EE04AB0:01CE5730] X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 62 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1369256725 news.xs4all.nl 15882 [2001:888:2000:d::a6]:46056 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:45751 Funny! I made a lot of assumptions regarding your requirements specificatio= n. Let me know if it isn't what you need:=0A= =0A= ### 1strow_average.py ###=0A= #Assuming you have CSV (comma separated values) files such as:=0A= #1.txt =3D '0=2C1=2C2=2C3=2C4=2C5=2C6=2C7=2C8=2C9\n' \=0A= #=A0=A0=A0=A0=A0=A0=A0 '10=2C11=2C12=2C13=2C14=2C15=2C16=2C17=2C18=2C19\n' = \=0A= #=A0=A0=A0=A0=A0=A0=A0 '20=2C21=2C22=2C23=2C24=2C25=2C26=2C27=2C28=2C29\n' = ...=0A= #=0A= # Usage: contents[file][row][column]=0A= # contents[0]=A0=A0=A0=A0=A0=A0 : file '1.txt'=0A= # contents[1][2]=A0=A0=A0 : 3rd row of file '2.txt'=0A= # contents[3][4][5] : 6th column of 5th row of file '4.txt'=0A= # len(contents)=A0=A0=A0=A0 : quantity of files=0A= # len(contents[4])=A0 : quantity of lines in file '5.txt'=0A= # len(contents[4][0]: quantity of values in the 1st line of file '5.txt'=0A= =0A= filenames =3D ['1.txt'=2C '2.txt'=2C '3.txt'=2C '4.txt'=2C '5.txt']=0A= contents=A0 =3D [[[int(z) for z in y.split('=2C')] for y in open(x).read().= split()] for x in filenames]=0A= s1c=A0 =3D [sum([r[0] for r in f]) for f in contents]=0A= a1r=A0 =3D [sum(f[0])/float(len(f[0])) for f in contents]=0A= print '\n'.join([x for x in ['File "{}" has 1st row average =3D {:.2f}'.for= mat(n=2Ca1r[i]) if s1c[i]=3D=3D50 else '' for i=2Cn in enumerate(filenames)= ] if x])=0A= =0A= =0A= ________________________________=0A= > From: wilkeira@gmail.com =0A= > Date: Thu=2C 23 May 2013 01:13:19 +0900 =0A= > Subject: file I/O and arithmetic calculation =0A= > To: python-list@python.org =0A= > =0A= > =0A= > Dear all=2C =0A= > =0A= > I would appreciate if someone could write a simple python code for the = =0A= > purpose below: =0A= > =0A= > I have five text files each of 10 columns by 10 rows as follows: =0A= > =0A= > =0A= > =0A= > file_one =3D 'C:/test/1.txt' =0A= > file_two =3D 'C:/test/2.txt' =0A= > . . . =0A= > file_five =3D 'C:/test/5.txt' =0A= > =0A= > I want to calculate the mean of first row (10 elements) for each file = =0A= > (5 files)=2C if mean of first column (10 elements) of each file (5 =0A= > files) is 50. =0A= > =0A= > Thank you in advance. =0A= > =0A= > Keira =0A= > =0A= > =0A= > -- http://mail.python.org/mailman/listinfo/python-list =