[Tutor] files question
antonmuhin íà rambler.ru
antonmuhin íà rambler.ru
Fri Jan 24 06:12:43 2003
Hello Ron,
Friday, January 24, 2003, 12:34:00 AM, you wrote:
RA> hold = []
RA> import string
RA>
RA> # OPEN AND READ A FILE
RA> def mylist():
RA> data = open('testing.txt', 'r')
RA> while 1:
RA> read_me = data.readline()
RA> if read_me == '':
RA> break
RA> no_n = read_me[:-1]
RA> split_me = string.split(no_n, '\t')
RA> hold.append(split_me)
RA> print hold
RA> data.close()
RA>
Maybe, this function could be improved:
for read_me in open(testing.txt', 'r'):
if read_me == '':
break
<snipped>
And if you use empty line to mark end of a file, you can get rid of
it:
for read_me in open(testing.txt', 'r'):
no_n = read_me[:-1]
etc...
This loop will terminate at the end of a file.
--
Best regards,
anton mailto:antonmuhin@rambler.ru