Re: [Tutor] manipulating data to delete blank spaces

2012-05-28 Thread Alan Gauld
On 28/05/12 23:15, Brendan Dornan wrote: Hi, I’d like to eliminate the no data fields in this XML file, since Tableau, the graphing software doesn’t allow this. What would be the easiest way to approach this? I’m a complete neophyte, having gone through the first 15 chapters of the “Think Like a

[Tutor] manipulating data to delete blank spaces

2012-05-28 Thread Brendan Dornan
Hi, I'd like to eliminate the no data fields in this XML file, since Tableau, the graphing software doesn't allow this. What would be the easiest way to approach this? I'm a complete neophyte, having gone through the first 15 chapters of the "Think Like a Computer Scientist." Long ways to go and a

Re: [Tutor] manipulating data

2007-11-15 Thread Tiger12506
ot;Alan Gauld" <[EMAIL PROTECTED]> Cc: Sent: Monday, November 12, 2007 2:43 PM Subject: Re: [Tutor] manipulating data >I try this, > > f = open('TEST1.MLC') > > fields = {} > > for line in f: >if line.split()[0] == 'Field': >fie

Re: [Tutor] manipulating data

2007-11-15 Thread Kent Johnson
Bryan Fodness wrote: > I try this, > > f = open('TEST1.MLC') > > fields = {} > > for line in f: > if line.split()[0] == 'Field': > field = int(line.split()[-1]) > elif line.split()[0] == 'Leaf': > fields[field] = line.split()[-1] > else: > line = f.next() > >

Re: [Tutor] manipulating data

2007-11-15 Thread Michael H. Goldwasser
On Monday November 12, 2007, Bryan Fodness wrote: >I try this, > >f = open('TEST1.MLC') > >fields = {} > >for line in f: >if line.split()[0] == 'Field': >field = int(line.split()[-1]) >elif line.split()[0] == 'Leaf': >fields[fie

Re: [Tutor] manipulating data

2007-11-15 Thread Bryan Fodness
I try this, f = open('TEST1.MLC') fields = {} for line in f: if line.split()[0] == 'Field': field = int(line.split()[-1]) elif line.split()[0] == 'Leaf': fields[field] = line.split()[-1] else: line = f.next() and get, Traceback (most recent call last): Fil

Re: [Tutor] manipulating data

2007-11-13 Thread Alan Gauld
"Bryan Fodness" <[EMAIL PROTECTED]> > f = open('TEST1.MLC') > fields = {} > for line in f: > the_line = line.split() > if the_line: >if the_line[0] == 'Field': > field = int(the_line[-1]) >elif the_line[0] == 'Leaf': > fields[field] = the_line[-1] > > which, sort of works, b

Re: [Tutor] manipulating data

2007-11-12 Thread Bryan Fodness
I have tried, f = open('TEST1.MLC') fields = {} for line in f: the_line = line.split() if the_line: if the_line[0] == 'Field': field = int(the_line[-1]) elif the_line[0] == 'Leaf': fields[field] = the_line[-1] which, sort of works, but it overwrites each value. On Nov 12,

Re: [Tutor] manipulating data

2007-11-12 Thread Alan Gauld
The lesson here is not to try to do two things at once... > file.next() > TypeError: descriptor 'next' of 'file' object needs an argument OK, My algorithm was meant to be pseudo code so file was not intended to be taken literally, its just a marker for an open file object. > And, it

Re: [Tutor] manipulating data

2007-11-12 Thread Bryan Fodness
Using the algorithm below, I get: Traceback (most recent call last): File "C:\Users\bryan\Documents\Yennes Medical Physics\mlcShape\findvalue.py", line 49, in file.next() TypeError: descriptor 'next' of 'file' object needs an argument And, it is true that I am trying to

Re: [Tutor] manipulating data

2007-11-12 Thread Ricardo Aráoz
Alan Gauld wrote: > "Bryan Fodness" <[EMAIL PROTECTED]> wrote in > >> fields = {} >> for line in open('data.txt') : >>if line : ## You shouldn't need this. >> if line.split()[0] == 'field' : >> field = int(line.split()[-1]) >> else : >> fields[field] = tuple(l

Re: [Tutor] manipulating data

2007-11-12 Thread ALAN GAULD
Brian, > if line.split()[0] == 'Field': >field = int(line.split()[-1]) > > IndexError: list index out of range You have blank lines in the file, when you try to call split on an empty string you get an empty list so trying to index any element will result in an Index error. That's

Re: [Tutor] manipulating data

2007-11-12 Thread Alan Gauld
"Bryan Fodness" <[EMAIL PROTECTED]> wrote in > fields = {} > for line in open('data.txt') : >if line : ## You shouldn't need this. > if line.split()[0] == 'field' : > field = int(line.split()[-1]) > else : > fields[field] = tuple(line.split()) > > fields[field

Re: [Tutor] manipulating data

2007-11-11 Thread Bryan Fodness
Using, fields = {} for line in open('data.txt') : if line : if line.split()[0] == 'field' : field = int(line.split()[-1]) else : fields[field] = tuple(line.split()) I get, fields[field] = tuple(line.split()) NameError: name 'field' is not defined On Nov

Re: [Tutor] manipulating data

2007-11-09 Thread Ricardo Aráoz
Kent Johnson wrote: > Bryan Fodness wrote: >> I would like to have my data in a format so that I can create a contour plot. >> >> My data is in a file with a format, where there may be multiple fields >> >> field = 1 >> >> 1a 0 > > If your data is really this regular, it is pretty easy to parse.

Re: [Tutor] manipulating data

2007-11-07 Thread Bryan Fodness
I also have some information at the beginning of the file and between each field. Is there a way to get the info at the beginning and tell it once it sees Leaf 1A to read the values for the next 120 and then repeat until there are no more Fields. File Rev = G Treatment = Dynamic Dose Last Name =

Re: [Tutor] manipulating data

2007-11-07 Thread Kent Johnson
Bryan Fodness wrote: > I also have some information at the beginning of the file and between > each field. Is there a way to get the info at the beginning and tell > it once it sees Leaf 1A to read the values for the next 120 and then > repeat until there are no more Fields. This should be a pret

Re: [Tutor] manipulating data

2007-11-07 Thread Kent Johnson
Bryan Fodness wrote: > I would like to have my data in a format so that I can create a contour plot. > > My data is in a file with a format, where there may be multiple fields > > field = 1 > > 1a0 If your data is really this regular, it is pretty easy to parse. A useful technique is to ac

[Tutor] manipulating data

2007-11-07 Thread Bryan Fodness
I would like to have my data in a format so that I can create a contour plot. My data is in a file with a format, where there may be multiple fields field = 1 1a 0 2a 0 3a 5 4a 5 5a 5 6a 5 7a 5 8a 5 9a 0 10a 0 1b 0 2b 0 3b 5 4b