Re: [Tutor] how to read from a txt file

2005-03-30 Thread Alan Gauld
> please help me! I'll try but I m9issed the early bit of this thread so jumping in cold... > > > so that i can read the text file created by this: > > > > > > self.filename = "%s\%s.txt" If the OS is Windows you might want to use two \\ just to be safe or alternatively use a forward slash inste

Re: [Tutor] how to read from a txt file

2005-03-30 Thread Liam Clarke
Nope, it's not that. You can just change your map(int, foo) calls to use float. (But that said, you don't need map, as you're operating on one item at a time.) Hmm try changing the following. for x in data: y = str(x).rstrip('\t\n') #This will remove any stray tabs or newlines on the end

Re: [Tutor] how to read from a txt file

2005-03-30 Thread Liam Clarke
>print temp1[x], temp2[x] This won't work. >>> fob = [] >>> gab = ["fooBar","Baz","aBBa"] >>> for line in gab: ... print line, ... x = line.replace('B', 'X') ... print x ... fob.append(x) ... print fob[line] ... fooBar fooXar Traceback (most recent call last): File "

Re: [Tutor] how to read from a txt file

2005-03-30 Thread Liam Clarke
So... you need those tabs? If you don't need them, go like this - > data_file = open(os.path.normpath(self.TextFile.GetValue()), 'r') for x in data: y = str(x) ( temp11, temp22, pyra11, pyra22, voltage11, current1) = y.split('\t') And that should be all your values, separated in string

Re: [Tutor] how to read from a txt file

2005-03-29 Thread jrlen balane
am getting desperate on this, please help me, I just can't figure out how to read those tabs please help me! On Tue, 29 Mar 2005 22:16:11 -0800, jrlen balane <[EMAIL PROTECTED]> wrote: > I need the string representation of the data read so that i can put it > on a wxGrid > while i am goin to nee

Re: [Tutor] how to read from a txt file

2005-03-29 Thread jrlen balane
I need the string representation of the data read so that i can put it on a wxGrid while i am goin to need the integer representation of the data so that i can plot it. anybody, please help!!! On Tue, 29 Mar 2005 20:56:16 -0800, jrlen balane <[EMAIL PROTECTED]> wrote: > how should i modify this

Re: [Tutor] how to read from a txt file

2005-03-29 Thread jrlen balane
how should i modify this data reader: (assumes that there is only one entry per line followed by '\n') data_file = open(os.path.normpath(self.TextFile.GetValue()), 'r') data = data_file.readlines() self.irradianceStrings = map(str, data) self.irradianceIntegers = map(int, data) self.IrradianceExe

Re: [Tutor] how to read from a txt file

2005-03-14 Thread Liam Clarke
Whoops, golden rule - "Never post untested code" Sorry. On Mon, 14 Mar 2005 21:05:44 -0500, Kent Johnson <[EMAIL PROTECTED]> wrote: > jrlen balane wrote: > > ok, i've done what sir Kent just said, my fault... > > > > but an error still occurs: > > Traceback (most recent call last): > > File "C:

Re: [Tutor] how to read from a txt file

2005-03-14 Thread Kent Johnson
jrlen balane wrote: ok, i've done what sir Kent just said, my fault... but an error still occurs: Traceback (most recent call last): File "C:\Python23\practices\opentxtprintlngnew.py", line 18, in -toplevel- print process(data) File "C:\Python23\practices\opentxtprintlngnew.py", line 10, in

Re: [Tutor] how to read from a txt file

2005-03-14 Thread jrlen balane
ok, i've done what sir Kent just said, my fault... but an error still occurs: Traceback (most recent call last): File "C:\Python23\practices\opentxtprintlngnew.py", line 18, in -toplevel- print process(data) File "C:\Python23\practices\opentxtprintlngnew.py", line 10, in process tempLi

Re: [Tutor] how to read from a txt file

2005-03-14 Thread Kent Johnson
jrlen balane wrote: import sys data_file = open('C:/Documents and Settings/nyer/Desktop/nyer.txt', 'r') data = data_file.readlines() def process(list_of_lines): data_points = [] for line in list_of_lines: try: tempLine = int(line) except TypeError: pr

Re: [Tutor] how to read from a txt file

2005-03-14 Thread jrlen balane
import sys data_file = open('C:/Documents and Settings/nyer/Desktop/nyer.txt', 'r') data = data_file.readlines() def process(list_of_lines): data_points = [] for line in list_of_lines: try: tempLine = int(line) except TypeError: print "Non numeric c

Re: [Tutor] how to read from a txt file

2005-03-14 Thread Kent Johnson
jrlen balane wrote: this is what i get after running this on IDLE: import sys data_file = open('C:/Documents and Settings/nyer/Desktop/nyer.txt', 'r') data = data_file.readlines() def process(list_of_lines): data_points = [] for line in list_of_lines: try: tempLine = i

Re: [Tutor] how to read from a txt file

2005-03-14 Thread jrlen balane
this is what i get after running this on IDLE: import sys data_file = open('C:/Documents and Settings/nyer/Desktop/nyer.txt', 'r') data = data_file.readlines() def process(list_of_lines): data_points = [] for line in list_of_lines: try: tempLine = int(line)

Re: [Tutor] how to read from a txt file

2005-03-14 Thread Liam Clarke
Oops, and I meant try: tempLine = int(line) Silly indent error. On Tue, 15 Mar 2005 12:52:49 +1300, Liam Clarke <[EMAIL PROTECTED]> wrote: > Well, a string "12345" when called through int() will come back as 12345. > > But, a string "foo", called through int(), will raise a TypeError. > >

Re: [Tutor] how to read from a txt file

2005-03-14 Thread Liam Clarke
Well, a string "12345" when called through int() will come back as 12345. But, a string "foo", called through int(), will raise a TypeError. So > import sys > > data_file = open('C:/Documents and Settings/nyer/Desktop/nyer.txt', 'r') > data = data_file.readlines() > > def process(list_of_l

Re: [Tutor] how to read from a txt file

2005-03-14 Thread jrlen balane
say i have the code that reads decimal value from a text file: import sys data_file = open('C:/Documents and Settings/nyer/Desktop/nyer.txt', 'r') data = data_file.readlines() def process(list_of_lines): data_points = [] for line in list_of_lines: data_points.append(int(line))

Re: [Tutor] how to read from a txt file

2005-02-17 Thread Kent Johnson
Brian van den Broek wrote: So, sorry, I don't know what's wrong with the code you sent me, and I fear that if I tried to work it out, I'd do more damage. I yield the floor as I am off to write "Don't post untested code 1000 times. for i in range(1000): print "Don't post untested code" (tested,

Re: [Tutor] how to read from a txt file

2005-02-17 Thread Gregor Lingl
Brian van den Broek schrieb: Brian van den Broek said unto the world upon 2005-02-17 03:51: > jrlen balane said unto the world upon 2005-02-17 02:41: sir, what seemed to be the problem with this: def process(list_of_lines): data_points = [] for line in list_of_lines: data_points.a

Re: [Tutor] how to read from a txt file

2005-02-17 Thread Danny Yoo
> >> Traceback (most recent call last): > >> File "C:\Python23\practices\opentxt", line 12, in -toplevel- > >> process(data) > >> File "C:\Python23\practices\opentxt", line 6, in process > >> data_points.append(int(line)) > >> ValueError: invalid literal for int(): Hi Brian, Ah, th

Re: [Tutor] how to read from a txt file

2005-02-17 Thread Brian van den Broek
Brian van den Broek said unto the world upon 2005-02-17 03:51: > jrlen balane said unto the world upon 2005-02-17 02:41: sir, what seemed to be the problem with this: def process(list_of_lines): data_points = [] for line in list_of_lines: data_points.append(int(line)) return dat

Re: [Tutor] how to read from a txt file

2005-02-17 Thread Brian van den Broek
Brian van den Broek said unto the world upon 2005-02-17 03:51: jrlen balane said unto the world upon 2005-02-17 02:41: sir, what seemed to be the problem with this: Hi, I think the traceback is my fault from an oversight in the code I sent you when you posted before. Sorry about that :-[ In cas

Re: [Tutor] how to read from a txt file

2005-02-17 Thread Brian van den Broek
jrlen balane said unto the world upon 2005-02-17 02:41: sir, what seemed to be the problem with this: def process(list_of_lines): data_points = [] for line in list_of_lines: data_points.append(int(line)) return data_points data_file = open('C:/Documents and Settings/nyer/Desktop

Re: [Tutor] how to read from a txt file

2005-02-13 Thread Alan Gauld
> ei guys, chill out! Its OK, we often get carried away on flights of fancy here :-) > what if i choose to numbered my data from 1-96 for example. how would > i be able to exclude the numbered part from the data part? You can use the string split() method to get a list of the components. Then se

Re: [Tutor] how to read from a txt file

2005-02-13 Thread Kent Johnson
Brian van den Broek wrote: YAGNI is a slogan of the Extreme and/or Agile programming community. Stands for You Aren't Going to Need It. The idea is, if you are thinking of doing something other than (another slogan) `the simplest thing that could possibly work' -- don't. The rational for complicati

Re: [Tutor] how to read from a txt file

2005-02-13 Thread Kent Johnson
jrlen balane wrote: and this line: data_points.append(int(line)) this would turn the string back to an integer, am i right? Yes. and on this one: data_points = [ int(line) for line in data_file ] this did not use any read(), is this already equal to readline()? so this would already store

Re: [Tutor] how to read from a txt file

2005-02-13 Thread Brian van den Broek
jrlen balane said unto the world upon 2005-02-13 18:45: ei guys, chill out! what if i choose to numbered my data from 1-96 for example. how would i be able to exclude the numbered part from the data part? and, mind if I ask, what's a YAGNI by the way? _

Re: [Tutor] how to read from a txt file

2005-02-13 Thread Alan Gauld
> what i know (chapter 7 of the tutorial): > 1) first, to open a txt file, i can use open() say: > f = open(*.txt, r) > a user can use the notepad to create the text file so i'll just open > it for reading. my problem now would be on reading the contents of the > file. OK So far >

Re: [Tutor] how to read from a txt file

2005-02-13 Thread jrlen balane
and this line: data_points.append(int(line)) this would turn the string back to an integer, am i right? and on this one: data_points = [ int(line) for line in data_file ] this did not use any read(), is this already equal to readline()? so this would already store all the data in the tx

Re: [Tutor] how to read from a txt file

2005-02-13 Thread jrlen balane
ei guys, chill out! what if i choose to numbered my data from 1-96 for example. how would i be able to exclude the numbered part from the data part? and, mind if I ask, what's a YAGNI by the way? ___ Tutor maillist - Tutor@python.org http://mail.pytho

Re: [Tutor] how to read from a txt file

2005-02-13 Thread Kent Johnson
Brian van den Broek wrote: Kent Johnson said unto the world upon 2005-02-13 14:04: Brian van den Broek wrote: Since you files are quite short, I'd do something like: data_file = open(thedata.txt, 'r') # note -- 'r' not r data = data_file.readlines() # returns a list of lines def process(list

Re: [Tutor] how to read from a txt file

2005-02-13 Thread Brian van den Broek
Kent Johnson said unto the world upon 2005-02-13 14:04: Brian van den Broek wrote: Since you files are quite short, I'd do something like: data_file = open(thedata.txt, 'r') # note -- 'r' not r data = data_file.readlines() # returns a list of lines def process(list_of_lines): data_points

Re: [Tutor] how to read from a txt file

2005-02-13 Thread Kent Johnson
Brian van den Broek wrote: Since you files are quite short, I'd do something like: data_file = open(thedata.txt, 'r') # note -- 'r' not r data = data_file.readlines() # returns a list of lines def process(list_of_lines): data_points = [] for line in list_of_lines: data_points

Re: [Tutor] how to read from a txt file

2005-02-13 Thread Brian van den Broek
jrlen balane said unto the world upon 2005-02-13 11:49: guys, how would i do this: i want to read from a text file the text file should contain should contain data (say, decimal value from 1-1200). there should be no other type of entry but decimal it should contain 96 data all in all, with each d