<div>
                    You just need to use the full path to the file - for example;
                </div><div><br></div><div>open('/path/to/file/p.txt')</div><div><br></div><div>If your on windows that will likely that with c:// etc.</div><div><br></div>
                <div></div>
                 
                <p style="color: #A0A0A8;">On Monday, 25 March 2013 at 11:28, Hedieh Ebrahimi wrote:</p>
                <blockquote type="cite" style="border-left-style:solid;border-width:1px;margin-left:0px;padding-left:10px;">
                    <span><div><div><div dir="ltr"><div><div><div><div><div>Hi all, <br><br></div>I am getting an input file and then im writing to an output file. <br><br></div>Right now they are both in the current working directory. <br><br></div>If I want to get the file from a separate directory and write the output to a separate directory not the same as the working directory, what should i do?<br>
<br></div>Thanks for help<br><br></div>Hedie<br></div><div><br><br><div>On 21 March 2013 18:01, Hedieh Ebrahimi <span dir="ltr"><<a href="mailto:hedieh.ebrahimi@amphos21.com" target="_blank">hedieh.ebrahimi@amphos21.com</a>></span> wrote:<br><blockquote type="cite"><div><div dir="ltr">#! /usr/bin/python<br><br># Python Program to read a text file, edit it and give a text file as output<br>
<br><br><br>#print("Python is really a great language,", "isnt it?");<br>#searchquery='TRAN'<div><br>
<br><br>with open('p.txt') as f1:<br> with open('Output.txt', 'a') as f2:<br>    for line in f1:<br>      if line.startswith(' TRAN'):<br></div>        #print("true")<br>        f2.write(line)<br>

        f2.write(f1.next())<br>        #f2.write(f1.next())<br>        ###columns = line.split()<br>        <br>#with open('Output.txt', 'a') as f2:<br>#f=open('Output.txt')<br>with open('Output.txt') as f2:<br>

  with open('Output2.txt') as f3:<br>    s=f2.readlines()<br>    str1 = ''.join(s)<br>    str1.split()<br>    print(str1)<br>    #f3.write(str1)<br>#print('Split this Sentence'.split())<br>#with open('Output2.txt') as f3:<br>

<br></div><div><div><div><br><br><div>On 21 March 2013 15:44, Hedieh Ebrahimi <span dir="ltr"><<a href="mailto:hedieh.ebrahimi@amphos21.com" target="_blank">hedieh.ebrahimi@amphos21.com</a>></span> wrote:<br><blockquote type="cite"><div><div dir="ltr"><div>Thanks guys for help with previous question. its working now.<br><br></div><div>I have another question. I need to extract information. so i now have a file like this :<br>

<br>TRAN      1 Time=  3.17098E-08 Dt=  3.17098E-08 [y] snes_conv_reason:    3<br>
  newton =  36 [    36] linear =    36 [        36] cuts =  0 [   0]<br>  --> max chng: dcmx=   5.0315E-08 dc/dt=   5.0315E-08 [mol/s]<br> TRAN      2 Time=  6.34196E-08 Dt=  3.17098E-08 [y] snes_conv_reason:    3<br>

  newton =   4 [    40] linear =     4 [        40] cuts =  0 [   0]<br>
  --> max chng: dcmx=   3.0785E-08 dc/dt=   3.0785E-08 [mol/s]<br> TRAN      3 Time=  1.26839E-07 Dt=  6.34196E-08 [y] snes_conv_reason:    3<br>  newton =   4 [    44] linear =     4 [        44] cuts =  0 [   0]<br>

  --> max chng: dcmx=   3.5161E-08 dc/dt=   1.7580E-08 [mol/s]<br>
<br>--------------------------------------------------------------------------------------<br>TRAN      <span style="background-color:rgb(255,153,0)">1</span> <span>Time</span>=  <span style="background-color:rgb(255,153,0)">3.17098E-08</span> <span>Dt</span>=  <span style="background-color:rgb(255,153,0)">3.17098E-08</span> [y] snes_conv_reason:    3<br>


  newton =  <span style="background-color:rgb(255,153,0)">36</span> [    36] linear =    <span style="background-color:rgb(255,153,0)">36</span> [        36] cuts =  <span style="background-color:rgb(255,153,0)">0</span> [   0]<br>


  --> max chng: dcmx=   5.0315E-08 dc/dt=   5.0315E-08 [mol/s]<br><br><br></div><div>In this file i need the following information to be extracted in each consequetive 3 lines. Could you please let me know how I can do this.<br>


<br></div><div>At the end i want to have a text file at the output producing this:<br><br></div><div>1 Time 3.17098E-08 Dt 3.17098E-08 newton 36 linear 36 cuts 0<br><br><br></div><div>Id appreciate any hints,<br></div><div>


ive just started python 2 days ago )))<br><br></div><div>thanks<br><br></div></div><div><div><div><br><br><div>On 21 March 2013 14:24, James Boyd <span dir="ltr"><<a href="mailto:james.boyd@hotmail.co.uk" target="_blank">james.boyd@hotmail.co.uk</a>></span> wrote:<br><blockquote type="cite"><div><div>Hi Heidi,<br>
<br>
Perhaps check your indentation, the code under the 'if' does not look indented correctly on my phone.  Also, assumption is that the p.txt file has some content where lines start with TRAN and the file/directory permissions are correct.<br>



<br>
I tried the code and works fine for me<br>
<br>
James<br>
<br>
On 21 Mar 2013, at 13:00, "Hedieh Ebrahimi" <<a href="mailto:hedieh.ebrahimi@amphos21.com" target="_blank">hedieh.ebrahimi@amphos21.com</a>> wrote:<br>
<br>
</div><div><div>> Hi all,<br>
><br>
> I am trying to write the below code to be able to read from a text file and fine lines that start with<br>
> TRAN  and then write this line and the next 2 following lines to another file called Output.txt.<br>
><br>
> my code is as below:<br>
><br>
><br>
> with open('p.txt') as f1:<br>
> with open('Output.txt', 'a') as f2:<br>
>   for line in f1:<br>
>     if line.startswith('TRAN'):<br>
>   print("true")<br>
>       f2.write(line)<br>
>       f2.write(f1.next())<br>
>       f2.write(f1.next())<br>
><br>
> 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.<br>
><br>
> Could somebody please tell me where is my error?<br>
><br>
> Thanks in advance<br>
> Heidi<br>
</div></div><div><div>> _______________________________________________<br>
> Glasgow mailing list<br>
> <a href="mailto:Glasgow@python.org" target="_blank">Glasgow@python.org</a><br>
> <a href="http://mail.python.org/mailman/listinfo/glasgow" target="_blank">http://mail.python.org/mailman/listinfo/glasgow</a><br>
_______________________________________________<br>
Glasgow mailing list<br>
<a href="mailto:Glasgow@python.org" target="_blank">Glasgow@python.org</a><br>
<a href="http://mail.python.org/mailman/listinfo/glasgow" target="_blank">http://mail.python.org/mailman/listinfo/glasgow</a><br>
</div></div></div></blockquote></div><br></div>
</div></div></div></blockquote></div><br></div>
</div></div></div></blockquote></div><br></div>
</div><div><div>_______________________________________________</div><div>Glasgow mailing list</div><div><a href="mailto:Glasgow@python.org">Glasgow@python.org</a></div><div><a href="http://mail.python.org/mailman/listinfo/glasgow">http://mail.python.org/mailman/listinfo/glasgow</a></div></div></div></span>
                 
                 
                 
                 
                </blockquote>
                 
                <div>
                    <br>
                </div>