On Sat, 22 Jan 2005, Kent Johnson wrote:
> Jay Loden wrote:
> > One simple solution is to do:
> >
> > fle = open(file)
> > contents = file.readlines()
> > file.close()
> > print contents[x] #or store this in a variable, whatever
>
> That is the simplest solution. If your file gets bigger and yo
Max Noel wrote:
On Jan 22, 2005, at 13:53, Kent Johnson wrote:
That is the simplest solution. If your file gets bigger and you don't
want to read it all at once, you can use enumerate to iterate the
lines and pick out the one you want:
f = open(...)
for i, line in enumerate(f):
if i==targetLin
On Jan 22, 2005, at 13:53, Kent Johnson wrote:
That is the simplest solution. If your file gets bigger and you don't
want to read it all at once, you can use enumerate to iterate the
lines and pick out the one you want:
f = open(...)
for i, line in enumerate(f):
if i==targetLine:
print lin
Jay Loden wrote:
One simple solution is to do:
fle = open(file)
contents = file.readlines()
file.close()
print contents[x] #or store this in a variable, whatever
That is the simplest solution. If your file gets bigger and you don't want to read it all at once,
you can use enumerate to iterate t
Jay Loden wrote:
One simple solution is to do:
fle = open(file)
contents = file.readlines()
file.close()
print contents[x] #or store this in a variable, whatever
-Jay
On Friday 21 January 2005 11:22, J. M. Strother wrote:
I have a text file containing 336 records.
I can read
One simple solution is to do:
fle = open(file)
contents = file.readlines()
file.close()
print contents[x] #or store this in a variable, whatever
-Jay
On Friday 21 January 2005 11:22, J. M. Strother wrote:
> I have a text file containing 336 records.
> I can read and print out the whole file w
J. M. Strother wrote:
I haveĀ a
text file containing 336 records.
I can read and print out the whole file without any problem.
What I want to do is read and print out one record only (chosen at
random). So I need to get to record x, select it, and then print it (or
store it in a variable)
I have a text file containing 336 records.
I can read and print out the whole file without any problem.
What I want to do is read and print out one record only (chosen at
random). So I need to get to record x, select it, and then print it (or
store it in a variable).
Can anyone tell me now to do