[python-advocacy] Nothing prints or writes to the output.txt
Aahz
aahz at pythoncraft.com
Sun Mar 24 14:42:01 CET 2013
BTW, in case nobody else told you, the advocacy list is not a good place
for getting help.
On Thu, Mar 21, 2013, Hedieh Ebrahimi wrote:
>
> Hi all,
>
> I am trying to write the below code to be able to read from a text file and
> fine lines that start with
> TRAN and then write this line and the next 2 following lines to another
> file called Output.txt.
>
> my code is as below:
>
>
> with open('p.txt') as f1:
> with open('Output.txt', 'a') as f2:
> for line in f1:
> if line.startswith('TRAN'):
> print("true")
> f2.write(line)
> f2.write(f1.next())
> f2.write(f1.next())
>
> but when i type python he.py in folder where the p.txt and Output.txt are
> located, nothing happens and no data is written to the output file.
>
> Could somebody please tell me where is my error?
>
> Thanks in advance
> Heidi
> _______________________________________________
> Advocacy mailing list
> Advocacy at python.org
> http://mail.python.org/mailman/listinfo/advocacy
--
Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/
"Many customs in this life persist because they ease friction and promote
productivity as a result of universal agreement, and whether they are
precisely the optimal choices is much less important." --Henry Spencer
More information about the Advocacy
mailing list