Great. That worked for me. I had some of my routines implemented in
Perl earlier. Now that I started using Python I am trying to do all my
automation scripts with Python. Thanks a ton
Jee
On 9/13/07, Peter Otten <[EMAIL PROTECTED]> wrote:
> Dennis Lee Bieber wrote:
>
> > for line in inp:
> >
> >
Dennis Lee Bieber wrote:
> for line in inp:
>
> will read one line at a time (I'm fairly sure the iterator doesn't
> attempt to buffer multiple lines behind the scenes)
You are wrong:
>>> open("tmp.txt", "w").writelines("%s\n" % (9*c) for c in "ABCDE")
>>> instream = open("tmp.txt")
>>> for li
Am Wed, 12 Sep 2007 17:28:08 -0500 schrieb Shankarjee Krishnamoorthi:
> I would prefer to use something with seek.
Writing Perl in any language?
> I am not able to use seek()
> with "for line in inp". Use tell and seek does not seem to do anything
> with the code. When I try to do
>
> for line
> for line in inp.readlines():
If you are now using readlines() instead of readline(), then
a) it is only used once to read all data into a container
b) you can access each element/line by it's relative number
data=open(filename, "r").readlines()
for eachline in data : (not readlines())
so try
I would prefer to use something with seek. I am not able to use seek()
with "for line in inp". Use tell and seek does not seem to do anything
with the code. When I try to do
for line in inp.readlines():
# Top of Loop
if not condition in line:
do_something
else:
fo
I'm assuming you know that python has a file.seek(), but you have to
know the number of bytes you want to move from the beginning of the
file or from the current location. You could save the length of the
previous record, and use file seek to backup and then move forward,
but it is simpler to save
Save the previous line in a variable if you want the previous line
only.
for line in inp:
# Perform some operations with line
if condition something:
print prev_line
print line
break
# I need to go back one line and use that line value
--> prev_line = line
I
Hi,
I am new to Python. I am trying to do the following
inp = open(my_file,'r')
for line in inp:
# Perform some operations with line
if condition something:
# Start re reading for that position again
for line in inp:
if some other condition