Re: file I/O and arithmetic calculation

2013-05-23 Thread Keira Wilson
not exactly for the homework, but as my starting point of learning thank you so much. -- http://mail.python.org/mailman/listinfo/python-list

RE: file I/O and arithmetic calculation

2013-05-23 Thread Carlos Nepomuceno
> From: denismfmcma...@gmail.com [...] >> Dear all who involved with responding to my question - Thank you so much >> for your nice code which really helped me. > > Hold on a sec? Someone posted code that gave the correct answer to a > homework question? > >

Re: file I/O and arithmetic calculation

2013-05-23 Thread Denis McMahon
On Thu, 23 May 2013 07:17:58 -0700, Keira Wilson wrote: > Dear all who involved with responding to my question - Thank you so much > for your nice code which really helped me. Hold on a sec? Someone posted code that gave the correct answer to a homework question? -- Denis McMahon, denismfmcma.

Re: file I/O and arithmetic calculation

2013-05-23 Thread Keira Wilson
Dear all who involved with responding to my question - Thank you so much for your nice code which really helped me. -- http://mail.python.org/mailman/listinfo/python-list

Re: file I/O and arithmetic calculation

2013-05-23 Thread Chris Angelico
On Thu, May 23, 2013 at 10:37 AM, Carlos Nepomuceno wrote: > >> From: oscar.j.benja...@gmail.com >> Date: Thu, 23 May 2013 01:34:37 +0100 >> Subject: Re: file I/O and arithmetic calculation >> To: carlosnepomuc...@outlook.com &g

Re: file I/O and arithmetic calculation

2013-05-23 Thread Oscar Benjamin
On 23 May 2013 04:15, Carlos Nepomuceno wrote: > The last line of my noob piece can be improved. So this is it: Most of it can be improved. > 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 file

RE: file I/O and arithmetic calculation

2013-05-22 Thread Carlos Nepomuceno
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

RE: file I/O and arithmetic calculation

2013-05-22 Thread Carlos Nepomuceno
> From: oscar.j.benja...@gmail.com > Date: Thu, 23 May 2013 01:34:37 +0100 > Subject: Re: file I/O and arithmetic calculation > To: carlosnepomuc...@outlook.com > CC: python-list@python.org > > On 23 May 2013 00:49, Carlos Nepomuceno

Re: file I/O and arithmetic calculation

2013-05-22 Thread Oscar Benjamin
On 23 May 2013 00:49, Carlos Nepomuceno wrote: > > The code is pretty obvious to me, I mean there's no obfuscation at all. I honestly can't tell if you're joking. -- http://mail.python.org/mailman/listinfo/python-list

RE: file I/O and arithmetic calculation

2013-05-22 Thread Carlos Nepomuceno
> From: denismfmcma...@gmail.com [...] > > import re > def v(s): > l=len(s) > t=0. > for i in range(l): > t=t+(abs(ord(s[i]))*1.) > return t/(l*1.) > for n in range(5): > m="c:/test/"+str(n+1)+".txt" > f=open(m,"r") > d=[] > t=0. > for l in range(10): > d=d+

Re: file I/O and arithmetic calculation

2013-05-22 Thread Denis McMahon
On Thu, 23 May 2013 01:13:19 +0900, Keira Wilson wrote: > I would appreciate if someone could write a simple python code for the > purpose below: Didn't have your data, so couldn't verify it completely, but try this: import re def v(s): l=len(s) t=0. for i in range(l): t=t+(abs(ord(s[i]))*1

RE: file I/O and arithmetic calculation

2013-05-22 Thread Carlos Nepomuceno
># contents[3][4][5] : 6th column of 5th row of file '4.txt' BTW, it should read # contents[3][4][5] : 6th value of 5th row of file '4.txt' -- http://mail.python.org/mailman/listinfo/python-list

RE: file I/O and arithmetic calculation

2013-05-22 Thread Carlos Nepomuceno
> From: oscar.j.benja...@gmail.com [...] > > Do you find this code easy to read? I wouldn't write something like > this and I certainly wouldn't use it when explaining something to a > beginner. > > Rather than repeated list comprehensions you should conside

Re: file I/O and arithmetic calculation

2013-05-22 Thread Oscar Benjamin
On 22 May 2013 22:05, Carlos Nepomuceno wrote: > > 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]

RE: file I/O and arithmetic calculation

2013-05-22 Thread Carlos Nepomuceno
Funny! I made a lot of assumptions regarding your requirements specification. Let me know if it isn't what you need: ### 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' \ #    '2

Re: file I/O and arithmetic calculation

2013-05-22 Thread Mark Lawrence
On 22/05/2013 17:13, Keira Wilson wrote: Dear all, I would appreciate if someone could write a simple python code for the purpose below: I have five text files each of 10 columns by 10 rows as follows: |file_one= 'C:/test/1.txt' file_two= 'C:/test/2.txt' . . . file_five= 'C:/test/5.txt'|

Re: File I/O

2007-05-09 Thread Klaas
On May 9, 2:43 pm, HMS Surprise <[EMAIL PROTECTED]> wrote: > > [lst.append(list(line.split())) for line in file] > > Thanks, this is the direction I wanted to go, BUT I must use v2.2 so > the line above gives me the error: > > AttributeError: __getitem__ > > But the write format will be helpful. (

Re: File I/O

2007-05-09 Thread HMS Surprise
> [lst.append(list(line.split())) for line in file] Thanks, this is the direction I wanted to go, BUT I must use v2.2 so the line above gives me the error: AttributeError: __getitem__ But the write format will be helpful. Thanks again, jh -- http://mail.python.org/mailman/listinfo/python-l

Re: File I/O

2007-05-09 Thread half . italian
On May 9, 2:13 pm, HMS Surprise <[EMAIL PROTECTED]> wrote: > If one has a list of lists such as > > lst = [['a','1'],['b','2']] > > is there a standard python idiom for writing and reading the pairs to/ > from a file? > > Thanks, > > jh These work. Assuming you can choose the format. Or you coul

Re: File I/O

2007-05-09 Thread Sönmez Kartal
Hi, As far as I know, Python doesn't have a specific thing to handle this. You could write a tiny function that would interpre element type of list's elements. It checks type, if it is a list then get that pair manually... If list is going like that 'a' - '1', 'b' - '2', you should use dictiona

Re: File I/O

2006-10-06 Thread uche . ogbuji
Ant wrote: > Kirt wrote: > ... > > i dont wanna parse the xml file.. > > > > Just open the file as: > > > > f=open('test.xml','a') > > > > and append a line "abc" before tag > > The other guys are right - you should look at something like > ElementTree which makes this sort of thing pretty easy,

Re: File I/O

2006-09-30 Thread Ant
Kirt wrote: ... > i dont wanna parse the xml file.. > > Just open the file as: > > f=open('test.xml','a') > > and append a line "abc" before tag The other guys are right - you should look at something like ElementTree which makes this sort of thing pretty easy, and is robust. But if you are sur

Re: File I/O

2006-09-30 Thread MonkeeSage
Diez B. Roggisch wrote: > Good to know that you can get drunk under any circumstances. +(++)1 heh! > I have seen a bazillion bad xml/html parsing-hacks using regexes and the > like, which stopped working after somehow the xml came all in one line, or > some other implicit assumption about its lay

Re: File I/O

2006-09-29 Thread Diez B. Roggisch
jimburton wrote: > > Diez B. Roggisch wrote: >> Kirt wrote: >> >> > >> > jimburton wrote: >> >> Kirt wrote: >> >> > Hi! I need some help in file I/O >> >> > >> >> > I have an xml file.. >> >> [snip] >> >> See http://diveintopython.org/xml_processing/ >> > >> > i dont wanna parse the xml file.. >>

Re: File I/O

2006-09-29 Thread jimburton
Diez B. Roggisch wrote: > Kirt wrote: > > > > > jimburton wrote: > >> Kirt wrote: > >> > Hi! I need some help in file I/O > >> > > >> > I have an xml file.. > >> [snip] > >> See http://diveintopython.org/xml_processing/ > > > > i dont wanna parse the xml file.. > > If you play soccer, do you insis

Re: File I/O

2006-09-29 Thread Diez B. Roggisch
Kirt wrote: > > jimburton wrote: >> Kirt wrote: >> > Hi! I need some help in file I/O >> > >> > I have an xml file.. >> [snip] >> See http://diveintopython.org/xml_processing/ > > i dont wanna parse the xml file.. If you play soccer, do you insist on playing with a baseball bat? The game is ca

Re: File I/O

2006-09-29 Thread jimburton
Kirt wrote: > i dont wanna parse the xml file.. > > Just open the file as: > > f=open('test.xml','a') > > and append a line "abc" before tag Use a regex to split the contents and insert new stuff, eg import re prog = prog = re.compile('^(.*)()', re.DOTALL) m = prog.search(f.read()) then m.gro

Re: File I/O

2006-09-29 Thread Kirt
jimburton wrote: > Kirt wrote: > > Hi! I need some help in file I/O > > > > I have an xml file.. > [snip] > See http://diveintopython.org/xml_processing/ i dont wanna parse the xml file.. Just open the file as: f=open('test.xml','a') and append a line "abc" before tag -- http://mail.python

Re: File I/O

2006-09-29 Thread Kirt
jimburton wrote: > Kirt wrote: > > Hi! I need some help in file I/O > > > > I have an xml file.. > [snip] > See http://diveintopython.org/xml_processing/ i dont wanna parse the xml file.. Just open the file as: f=open('test.xml','a') and write a line "abc" before tag http://mail.python.org/ma

Re: File I/O

2006-09-29 Thread jimburton
Kirt wrote: > Hi! I need some help in file I/O > > I have an xml file.. [snip] See http://diveintopython.org/xml_processing/ -- http://mail.python.org/mailman/listinfo/python-list