From no-reply at dougalmatthews.com Mon Mar 18 09:01:12 2013 From: no-reply at dougalmatthews.com (no-reply at dougalmatthews.com) Date: Mon, 18 Mar 2013 08:01:12 +0000 Subject: [Python Glasgow] Python Glasgow Pub Meetup on Monday 25th of March in Blackfriars Message-ID: <20130318080111.2.30439@f5709b5d-f90e-4ca4-b1c9-8c243d74ed45.private.dyno.runtime.heroku.com> Hi All, The next Python Glasgow event will be a Python Glasgow Pub Meetup in 7 days on the Monday 25th of March at Blackfriars, 36 Bell Street, Glasgow, G1 1LG. There will be a printed Python logo on the table so everyone can find us. Look forward to seeing you all there! Cheers, Dougal From hedieh.ebrahimi at amphos21.com Thu Mar 21 14:00:31 2013 From: hedieh.ebrahimi at amphos21.com (Hedieh Ebrahimi) Date: Thu, 21 Mar 2013 14:00:31 +0100 Subject: [Python Glasgow] How to write lines that start with TRAN to another output file Message-ID: 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 -------------- next part -------------- An HTML attachment was scrubbed... URL: From dougal85 at gmail.com Thu Mar 21 14:06:43 2013 From: dougal85 at gmail.com (Dougal Matthews) Date: Thu, 21 Mar 2013 13:06:43 +0000 Subject: [Python Glasgow] Python Glasgow Dojo next month 8th April Message-ID: Hey all, As you seen in the previous email - we will be meeting again at Blackfriars on the 4th Monday. That's the 25th this month. Then next month we are going be moving to the second Tuesday and to kick it off we will start with running our first dojo! Twig have kindly offered to host us in their office and will be providing some pizza and beer. Their offices are fairly central, a few minutes walk from Charing Cross. Also, by the way, Twig are hiring: https://gist.github.com/aaronbassett/4768919 For those of you that don't know, a dojo is a fun coding event where we split into teams and hack on a problem for about 90 minutes. The focus is on getting something working and making progress rather than on code quality, so feel free to take on the problem any way you wish! Then at the end we will share what we found. It's great fun and great for learning too. All levels of Python are welcome as you can contribute to your team with ideas and discussion. We will be following the format of the London Python Dojo - to read more about what to expect look here: http://ntoll.org/article/how-to-run-an-awesome-code-dojo Tickets are available now at https://pythonglasgow.eventwax.com/dojo-april-2013 I'm really looking forward to it and hoping to see you there! Cheers, Dougal -------------- next part -------------- An HTML attachment was scrubbed... URL: From dougal85 at gmail.com Thu Mar 21 14:22:27 2013 From: dougal85 at gmail.com (Dougal Matthews) Date: Thu, 21 Mar 2013 13:22:27 +0000 Subject: [Python Glasgow] How to write lines that start with TRAN to another output file In-Reply-To: References: Message-ID: <2CA53528FB384A4F8A56693A32DE0280@gmail.com> On Thursday, 21 March 2013 at 13:00, 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? > I tried your code and it worked fine for me. Here is my output: http://dpaste.com/1030136/ You can see the code, then input file, the output of it running (true printed three times) and then the output file contents. The only thing I can think of is the file permissions. What output do you see when you run the code? -------------- next part -------------- An HTML attachment was scrubbed... URL: From kevin.mcdermott at gmail.com Thu Mar 21 14:13:37 2013 From: kevin.mcdermott at gmail.com (Kevin McDermott) Date: Thu, 21 Mar 2013 13:13:37 +0000 Subject: [Python Glasgow] How to write lines that start with TRAN to another output file In-Reply-To: References: Message-ID: <514B0781.3080708@gmail.com> Hello > 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()) > Assuming that your code is indented correctly...this looks ok. > 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? Testing it against a file that looks like this... TRAN line1 line2 TRAN line3 line4 NOTHING NOTHING NOTHING TRAN line5 line6 Works fine. Kevin From james.boyd at hotmail.co.uk Thu Mar 21 14:24:10 2013 From: james.boyd at hotmail.co.uk (James Boyd) Date: Thu, 21 Mar 2013 13:24:10 +0000 Subject: [Python Glasgow] How to write lines that start with TRAN to another output file In-Reply-To: References: Message-ID: Hi Heidi, 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. I tried the code and works fine for me James On 21 Mar 2013, at 13:00, "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 > _______________________________________________ > Glasgow mailing list > Glasgow at python.org > http://mail.python.org/mailman/listinfo/glasgow From james.boyd at hotmail.co.uk Thu Mar 21 14:24:51 2013 From: james.boyd at hotmail.co.uk (James Boyd) Date: Thu, 21 Mar 2013 13:24:51 +0000 Subject: [Python Glasgow] How to write lines that start with TRAN to another output file In-Reply-To: References: Message-ID: Hi Heidi, 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. I tried the code and works fine for me James On 21 Mar 2013, at 13:00, "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 > _______________________________________________ > Glasgow mailing list > Glasgow at python.org > http://mail.python.org/mailman/listinfo/glasgow From hedieh.ebrahimi at amphos21.com Thu Mar 21 15:44:53 2013 From: hedieh.ebrahimi at amphos21.com (Hedieh Ebrahimi) Date: Thu, 21 Mar 2013 15:44:53 +0100 Subject: [Python Glasgow] How to write lines that start with TRAN to another output file In-Reply-To: References: Message-ID: Thanks guys for help with previous question. its working now. I have another question. I need to extract information. so i now have a file like this : TRAN 1 Time= 3.17098E-08 Dt= 3.17098E-08 [y] snes_conv_reason: 3 newton = 36 [ 36] linear = 36 [ 36] cuts = 0 [ 0] --> max chng: dcmx= 5.0315E-08 dc/dt= 5.0315E-08 [mol/s] TRAN 2 Time= 6.34196E-08 Dt= 3.17098E-08 [y] snes_conv_reason: 3 newton = 4 [ 40] linear = 4 [ 40] cuts = 0 [ 0] --> max chng: dcmx= 3.0785E-08 dc/dt= 3.0785E-08 [mol/s] TRAN 3 Time= 1.26839E-07 Dt= 6.34196E-08 [y] snes_conv_reason: 3 newton = 4 [ 44] linear = 4 [ 44] cuts = 0 [ 0] --> max chng: dcmx= 3.5161E-08 dc/dt= 1.7580E-08 [mol/s] -------------------------------------------------------------------------------------- TRAN 1 Time= 3.17098E-08 Dt= 3.17098E-08 [y] snes_conv_reason: 3 newton = 36 [ 36] linear = 36 [ 36] cuts = 0 [ 0] --> max chng: dcmx= 5.0315E-08 dc/dt= 5.0315E-08 [mol/s] 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. At the end i want to have a text file at the output producing this: 1 Time 3.17098E-08 Dt 3.17098E-08 newton 36 linear 36 cuts 0 Id appreciate any hints, ive just started python 2 days ago ))) thanks On 21 March 2013 14:24, James Boyd wrote: > Hi Heidi, > > 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. > > I tried the code and works fine for me > > James > > On 21 Mar 2013, at 13:00, "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 > > _______________________________________________ > > Glasgow mailing list > > Glasgow at python.org > > http://mail.python.org/mailman/listinfo/glasgow > _______________________________________________ > Glasgow mailing list > Glasgow at python.org > http://mail.python.org/mailman/listinfo/glasgow > -------------- next part -------------- An HTML attachment was scrubbed... URL: From hedieh.ebrahimi at amphos21.com Thu Mar 21 15:54:29 2013 From: hedieh.ebrahimi at amphos21.com (Hedieh Ebrahimi) Date: Thu, 21 Mar 2013 15:54:29 +0100 Subject: [Python Glasgow] (no subject) Message-ID: Thanks guys for help with previous question. its working now. I have another question. I need to extract information. so i now have a file like this : TRAN 1 Time= 3.17098E-08 Dt= 3.17098E-08 [y] snes_conv_reason: 3 newton = 36 [ 36] linear = 36 [ 36] cuts = 0 [ 0] --> max chng: dcmx= 5.0315E-08 dc/dt= 5.0315E-08 [mol/s] TRAN 2 Time= 6.34196E-08 Dt= 3.17098E-08 [y] snes_conv_reason: 3 newton = 4 [ 40] linear = 4 [ 40] cuts = 0 [ 0] --> max chng: dcmx= 3.0785E-08 dc/dt= 3.0785E-08 [mol/s] TRAN 3 Time= 1.26839E-07 Dt= 6.34196E-08 [y] snes_conv_reason: 3 newton = 4 [ 44] linear = 4 [ 44] cuts = 0 [ 0] --> max chng: dcmx= 3.5161E-08 dc/dt= 1.7580E-08 [mol/s] -------------------------------------------------------------------------------------- TRAN 1 Time= 3.17098E-08 Dt= 3.17098E-08 [y] snes_conv_reason: 3 newton = 36 [ 36] linear = 36 [ 36] cuts = 0 [ 0] --> max chng: dcmx= 5.0315E-08 dc/dt= 5.0315E-08 [mol/s] 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. At the end i want to have a text file at the output producing this: 1 Time 3.17098E-08 Dt 3.17098E-08 newton 36 linear 36 cuts 0 Id appreciate any hints, ive just started python 2 days ago ))) thanks -------------- next part -------------- An HTML attachment was scrubbed... URL: From hedieh.ebrahimi at amphos21.com Thu Mar 21 18:01:27 2013 From: hedieh.ebrahimi at amphos21.com (Hedieh Ebrahimi) Date: Thu, 21 Mar 2013 18:01:27 +0100 Subject: [Python Glasgow] How to write lines that start with TRAN to another output file In-Reply-To: References: Message-ID: #! /usr/bin/python # Python Program to read a text file, edit it and give a text file as output #print("Python is really a great language,", "isnt it?"); #searchquery='TRAN' 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()) ###columns = line.split() #with open('Output.txt', 'a') as f2: #f=open('Output.txt') with open('Output.txt') as f2: with open('Output2.txt') as f3: s=f2.readlines() str1 = ''.join(s) str1.split() print(str1) #f3.write(str1) #print('Split this Sentence'.split()) #with open('Output2.txt') as f3: On 21 March 2013 15:44, Hedieh Ebrahimi wrote: > Thanks guys for help with previous question. its working now. > > I have another question. I need to extract information. so i now have a > file like this : > > TRAN 1 Time= 3.17098E-08 Dt= 3.17098E-08 [y] snes_conv_reason: 3 > newton = 36 [ 36] linear = 36 [ 36] cuts = 0 [ 0] > --> max chng: dcmx= 5.0315E-08 dc/dt= 5.0315E-08 [mol/s] > TRAN 2 Time= 6.34196E-08 Dt= 3.17098E-08 [y] snes_conv_reason: 3 > newton = 4 [ 40] linear = 4 [ 40] cuts = 0 [ 0] > --> max chng: dcmx= 3.0785E-08 dc/dt= 3.0785E-08 [mol/s] > TRAN 3 Time= 1.26839E-07 Dt= 6.34196E-08 [y] snes_conv_reason: 3 > newton = 4 [ 44] linear = 4 [ 44] cuts = 0 [ 0] > --> max chng: dcmx= 3.5161E-08 dc/dt= 1.7580E-08 [mol/s] > > > -------------------------------------------------------------------------------------- > TRAN 1 Time= 3.17098E-08 Dt= 3.17098E-08 [y] snes_conv_reason: 3 > newton = 36 [ 36] linear = 36 [ 36] cuts = 0 [ 0] > --> max chng: dcmx= 5.0315E-08 dc/dt= 5.0315E-08 [mol/s] > > > 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. > > At the end i want to have a text file at the output producing this: > > 1 Time 3.17098E-08 Dt 3.17098E-08 newton 36 linear 36 cuts 0 > > > Id appreciate any hints, > ive just started python 2 days ago ))) > > thanks > > > > On 21 March 2013 14:24, James Boyd wrote: > >> Hi Heidi, >> >> 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. >> >> I tried the code and works fine for me >> >> James >> >> On 21 Mar 2013, at 13:00, "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 >> > _______________________________________________ >> > Glasgow mailing list >> > Glasgow at python.org >> > http://mail.python.org/mailman/listinfo/glasgow >> _______________________________________________ >> Glasgow mailing list >> Glasgow at python.org >> http://mail.python.org/mailman/listinfo/glasgow >> > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From tomwalker0472 at gmail.com Sat Mar 23 17:25:53 2013 From: tomwalker0472 at gmail.com (Tom Walker) Date: Sat, 23 Mar 2013 16:25:53 +0000 Subject: [Python Glasgow] Time? Message-ID: What time is the meet up at Blackfriars on the 25th? I am a beginner but would love to come along. Tom -------------- next part -------------- An HTML attachment was scrubbed... URL: From dougal85 at gmail.com Sat Mar 23 17:28:25 2013 From: dougal85 at gmail.com (Dougal Matthews) Date: Sat, 23 Mar 2013 16:28:25 +0000 Subject: [Python Glasgow] Time? In-Reply-To: References: Message-ID: <7AA07A9EE3E14309977C74B9871E67FF@gmail.com> Hey Tom, Sorry for not including the time. I'm usually there early - from bout 6 but most arrive about 6:30-7 I think. Also, make sure you read this email: http://mail.python.org/pipermail/glasgow/2013-March/000023.html We are changing the night and arranging a Dojo for next month which should be great fun (and great to learn!) Look forward to seeing you there! Dougal On Saturday, 23 March 2013 at 16:25, Tom Walker wrote: > What time is the meet up at Blackfriars on the 25th? > > I am a beginner but would love to come along. > > Tom > _______________________________________________ > Glasgow mailing list > Glasgow at python.org (mailto:Glasgow at python.org) > http://mail.python.org/mailman/listinfo/glasgow > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From robomotic at gmail.com Sat Mar 23 18:18:35 2013 From: robomotic at gmail.com (Paolo Di Prodi) Date: Sat, 23 Mar 2013 17:18:35 +0000 Subject: [Python Glasgow] Time? In-Reply-To: <7AA07A9EE3E14309977C74B9871E67FF@gmail.com> References: <7AA07A9EE3E14309977C74B9871E67FF@gmail.com> Message-ID: Guys I am sorry but I am very ill and will not attend. Cheers. On 23 March 2013 16:28, Dougal Matthews wrote: > Hey Tom, > > Sorry for not including the time. I'm usually there early - from bout 6 > but most arrive about 6:30-7 I think. > > Also, make sure you read this email: > http://mail.python.org/pipermail/glasgow/2013-March/000023.html > We are changing the night and arranging a Dojo for next month which should > be great fun (and great to learn!) > > Look forward to seeing you there! > > Dougal > > On Saturday, 23 March 2013 at 16:25, Tom Walker wrote: > > What time is the meet up at Blackfriars on the 25th? > > I am a beginner but would love to come along. > > Tom > _______________________________________________ > Glasgow mailing list > Glasgow at python.org > http://mail.python.org/mailman/listinfo/glasgow > > > > _______________________________________________ > Glasgow mailing list > Glasgow at python.org > http://mail.python.org/mailman/listinfo/glasgow > > -- Dr. Paolo Di Prodi -------------- next part -------------- An HTML attachment was scrubbed... URL: From dougal85 at gmail.com Sat Mar 23 18:21:36 2013 From: dougal85 at gmail.com (Dougal Matthews) Date: Sat, 23 Mar 2013 17:21:36 +0000 Subject: [Python Glasgow] Time? In-Reply-To: References: <7AA07A9EE3E14309977C74B9871E67FF@gmail.com> Message-ID: <3A347B0C-E369-457E-8504-ECC376849428@gmail.com> No worries - hope you get better soon and in time for the dojo! Sent from my iPhone On 23 Mar 2013, at 17:18, Paolo Di Prodi wrote: > Guys I am sorry but I am very ill and will not attend. > > Cheers. > > On 23 March 2013 16:28, Dougal Matthews wrote: >> Hey Tom, >> >> Sorry for not including the time. I'm usually there early - from bout 6 but most arrive about 6:30-7 I think. >> >> Also, make sure you read this email: http://mail.python.org/pipermail/glasgow/2013-March/000023.html >> We are changing the night and arranging a Dojo for next month which should be great fun (and great to learn!) >> >> Look forward to seeing you there! >> >> Dougal >> >> On Saturday, 23 March 2013 at 16:25, Tom Walker wrote: >> >>> What time is the meet up at Blackfriars on the 25th? >>> >>> I am a beginner but would love to come along. >>> >>> Tom >>> _______________________________________________ >>> Glasgow mailing list >>> Glasgow at python.org >>> http://mail.python.org/mailman/listinfo/glasgow >> >> >> _______________________________________________ >> Glasgow mailing list >> Glasgow at python.org >> http://mail.python.org/mailman/listinfo/glasgow > > > > -- > Dr. Paolo Di Prodi > > _______________________________________________ > Glasgow mailing list > Glasgow at python.org > http://mail.python.org/mailman/listinfo/glasgow -------------- next part -------------- An HTML attachment was scrubbed... URL: From no-reply at dougalmatthews.com Sun Mar 24 09:00:13 2013 From: no-reply at dougalmatthews.com (no-reply at dougalmatthews.com) Date: Sun, 24 Mar 2013 08:00:13 +0000 Subject: [Python Glasgow] Python Glasgow Pub Meetup on Monday 25th of March in Blackfriars Message-ID: <20130324080012.2.7179@ecfabf8b-3a83-4ed5-a9ba-1af260065878.private.dyno.runtime.heroku.com> Hi All, The next Python Glasgow event will be a Python Glasgow Pub Meetup in 1 days on the Monday 25th of March at Blackfriars, 36 Bell Street, Glasgow, G1 1LG. There will be a printed Python logo on the table so everyone can find us. Look forward to seeing you all there! Cheers, Dougal From hedieh.ebrahimi at amphos21.com Mon Mar 25 12:28:15 2013 From: hedieh.ebrahimi at amphos21.com (Hedieh Ebrahimi) Date: Mon, 25 Mar 2013 12:28:15 +0100 Subject: [Python Glasgow] How to write lines that start with TRAN to another output file In-Reply-To: References: Message-ID: Hi all, I am getting an input file and then im writing to an output file. Right now they are both in the current working directory. 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? Thanks for help Hedie On 21 March 2013 18:01, Hedieh Ebrahimi wrote: > #! /usr/bin/python > > # Python Program to read a text file, edit it and give a text file as > output > > > > #print("Python is really a great language,", "isnt it?"); > #searchquery='TRAN' > > > > 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()) > ###columns = line.split() > > #with open('Output.txt', 'a') as f2: > #f=open('Output.txt') > with open('Output.txt') as f2: > with open('Output2.txt') as f3: > s=f2.readlines() > str1 = ''.join(s) > str1.split() > print(str1) > #f3.write(str1) > #print('Split this Sentence'.split()) > #with open('Output2.txt') as f3: > > > > On 21 March 2013 15:44, Hedieh Ebrahimi wrote: > >> Thanks guys for help with previous question. its working now. >> >> I have another question. I need to extract information. so i now have a >> file like this : >> >> TRAN 1 Time= 3.17098E-08 Dt= 3.17098E-08 [y] snes_conv_reason: 3 >> newton = 36 [ 36] linear = 36 [ 36] cuts = 0 [ 0] >> --> max chng: dcmx= 5.0315E-08 dc/dt= 5.0315E-08 [mol/s] >> TRAN 2 Time= 6.34196E-08 Dt= 3.17098E-08 [y] snes_conv_reason: >> 3 >> newton = 4 [ 40] linear = 4 [ 40] cuts = 0 [ 0] >> --> max chng: dcmx= 3.0785E-08 dc/dt= 3.0785E-08 [mol/s] >> TRAN 3 Time= 1.26839E-07 Dt= 6.34196E-08 [y] snes_conv_reason: >> 3 >> newton = 4 [ 44] linear = 4 [ 44] cuts = 0 [ 0] >> --> max chng: dcmx= 3.5161E-08 dc/dt= 1.7580E-08 [mol/s] >> >> >> -------------------------------------------------------------------------------------- >> TRAN 1 Time= 3.17098E-08 Dt= 3.17098E-08 [y] snes_conv_reason: >> 3 >> newton = 36 [ 36] linear = 36 [ 36] cuts = 0 [ 0] >> --> max chng: dcmx= 5.0315E-08 dc/dt= 5.0315E-08 [mol/s] >> >> >> 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. >> >> At the end i want to have a text file at the output producing this: >> >> 1 Time 3.17098E-08 Dt 3.17098E-08 newton 36 linear 36 cuts 0 >> >> >> Id appreciate any hints, >> ive just started python 2 days ago ))) >> >> thanks >> >> >> >> On 21 March 2013 14:24, James Boyd wrote: >> >>> Hi Heidi, >>> >>> 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. >>> >>> I tried the code and works fine for me >>> >>> James >>> >>> On 21 Mar 2013, at 13:00, "Hedieh Ebrahimi" < >>> hedieh.ebrahimi at amphos21.com> 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 >>> > _______________________________________________ >>> > Glasgow mailing list >>> > Glasgow at python.org >>> > http://mail.python.org/mailman/listinfo/glasgow >>> _______________________________________________ >>> Glasgow mailing list >>> Glasgow at python.org >>> http://mail.python.org/mailman/listinfo/glasgow >>> >> >> > -------------- next part -------------- An HTML attachment was scrubbed... URL: From dougal85 at gmail.com Mon Mar 25 12:32:35 2013 From: dougal85 at gmail.com (Dougal Matthews) Date: Mon, 25 Mar 2013 11:32:35 +0000 Subject: [Python Glasgow] How to write lines that start with TRAN to another output file In-Reply-To: References: Message-ID: <2C379F859C29430F9EE8AE31679D9914@gmail.com> You just need to use the full path to the file - for example; open('/path/to/file/p.txt') If your on windows that will likely that with c:// etc. On Monday, 25 March 2013 at 11:28, Hedieh Ebrahimi wrote: > Hi all, > > I am getting an input file and then im writing to an output file. > > Right now they are both in the current working directory. > > 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? > > Thanks for help > > Hedie > > > On 21 March 2013 18:01, Hedieh Ebrahimi wrote: > > #! /usr/bin/python > > > > # Python Program to read a text file, edit it and give a text file as output > > > > > > > > #print("Python is really a great language,", "isnt it?"); > > #searchquery='TRAN' > > > > > > > > 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()) > > ###columns = line.split() > > > > #with open('Output.txt', 'a') as f2: > > #f=open('Output.txt') > > with open('Output.txt') as f2: > > with open('Output2.txt') as f3: > > s=f2.readlines() > > str1 = ''.join(s) > > str1.split() > > print(str1) > > #f3.write(str1) > > #print('Split this Sentence'.split()) > > #with open('Output2.txt') as f3: > > > > > > > > On 21 March 2013 15:44, Hedieh Ebrahimi wrote: > > > Thanks guys for help with previous question. its working now. > > > > > > I have another question. I need to extract information. so i now have a file like this : > > > > > > TRAN 1 Time= 3.17098E-08 Dt= 3.17098E-08 [y] snes_conv_reason: 3 > > > newton = 36 [ 36] linear = 36 [ 36] cuts = 0 [ 0] > > > --> max chng: dcmx= 5.0315E-08 dc/dt= 5.0315E-08 [mol/s] > > > TRAN 2 Time= 6.34196E-08 Dt= 3.17098E-08 [y] snes_conv_reason: 3 > > > newton = 4 [ 40] linear = 4 [ 40] cuts = 0 [ 0] > > > --> max chng: dcmx= 3.0785E-08 dc/dt= 3.0785E-08 [mol/s] > > > TRAN 3 Time= 1.26839E-07 Dt= 6.34196E-08 [y] snes_conv_reason: 3 > > > newton = 4 [ 44] linear = 4 [ 44] cuts = 0 [ 0] > > > --> max chng: dcmx= 3.5161E-08 dc/dt= 1.7580E-08 [mol/s] > > > > > > -------------------------------------------------------------------------------------- > > > TRAN 1 Time= 3.17098E-08 Dt= 3.17098E-08 [y] snes_conv_reason: 3 > > > newton = 36 [ 36] linear = 36 [ 36] cuts = 0 [ 0] > > > --> max chng: dcmx= 5.0315E-08 dc/dt= 5.0315E-08 [mol/s] > > > > > > > > > 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. > > > > > > At the end i want to have a text file at the output producing this: > > > > > > 1 Time 3.17098E-08 Dt 3.17098E-08 newton 36 linear 36 cuts 0 > > > > > > > > > Id appreciate any hints, > > > ive just started python 2 days ago ))) > > > > > > thanks > > > > > > > > > > > > On 21 March 2013 14:24, James Boyd wrote: > > > > Hi Heidi, > > > > > > > > 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. > > > > > > > > I tried the code and works fine for me > > > > > > > > James > > > > > > > > On 21 Mar 2013, at 13:00, "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 > > > > > _______________________________________________ > > > > > Glasgow mailing list > > > > > Glasgow at python.org (mailto:Glasgow at python.org) > > > > > http://mail.python.org/mailman/listinfo/glasgow > > > > _______________________________________________ > > > > Glasgow mailing list > > > > Glasgow at python.org (mailto:Glasgow at python.org) > > > > http://mail.python.org/mailman/listinfo/glasgow > > > > > > > _______________________________________________ > Glasgow mailing list > Glasgow at python.org (mailto:Glasgow at python.org) > http://mail.python.org/mailman/listinfo/glasgow > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From hedieh.ebrahimi at amphos21.com Mon Mar 25 13:36:17 2013 From: hedieh.ebrahimi at amphos21.com (Hedieh Ebrahimi) Date: Mon, 25 Mar 2013 13:36:17 +0100 Subject: [Python Glasgow] How to write lines that start with TRAN to another output file In-Reply-To: <2C379F859C29430F9EE8AE31679D9914@gmail.com> References: <2C379F859C29430F9EE8AE31679D9914@gmail.com> Message-ID: Thanks Dougal, but one question, the full path works if I am working on this computer and with this user. Is there anyway I could set this if i am planning to run the code on another system? Also I am getting output to an output.txt file which I have already created. Is there anyway to ask python to create a text file ? I checked python File I\O but I couldnt find anything on creating files. Id appreciate any help Thanks On 25 March 2013 12:32, Dougal Matthews wrote: > You just need to use the full path to the file - for example; > > open('/path/to/file/p.txt') > > If your on windows that will likely that with c:// etc. > > On Monday, 25 March 2013 at 11:28, Hedieh Ebrahimi wrote: > > Hi all, > > I am getting an input file and then im writing to an output file. > > Right now they are both in the current working directory. > > 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? > > Thanks for help > > Hedie > > > On 21 March 2013 18:01, Hedieh Ebrahimi wrote: > > #! /usr/bin/python > > # Python Program to read a text file, edit it and give a text file as > output > > > > #print("Python is really a great language,", "isnt it?"); > #searchquery='TRAN' > > > > 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()) > ###columns = line.split() > > #with open('Output.txt', 'a') as f2: > #f=open('Output.txt') > with open('Output.txt') as f2: > with open('Output2.txt') as f3: > s=f2.readlines() > str1 = ''.join(s) > str1.split() > print(str1) > #f3.write(str1) > #print('Split this Sentence'.split()) > #with open('Output2.txt') as f3: > > > > On 21 March 2013 15:44, Hedieh Ebrahimi wrote: > > Thanks guys for help with previous question. its working now. > > I have another question. I need to extract information. so i now have a > file like this : > > TRAN 1 Time= 3.17098E-08 Dt= 3.17098E-08 [y] snes_conv_reason: 3 > newton = 36 [ 36] linear = 36 [ 36] cuts = 0 [ 0] > --> max chng: dcmx= 5.0315E-08 dc/dt= 5.0315E-08 [mol/s] > TRAN 2 Time= 6.34196E-08 Dt= 3.17098E-08 [y] snes_conv_reason: 3 > newton = 4 [ 40] linear = 4 [ 40] cuts = 0 [ 0] > --> max chng: dcmx= 3.0785E-08 dc/dt= 3.0785E-08 [mol/s] > TRAN 3 Time= 1.26839E-07 Dt= 6.34196E-08 [y] snes_conv_reason: 3 > newton = 4 [ 44] linear = 4 [ 44] cuts = 0 [ 0] > --> max chng: dcmx= 3.5161E-08 dc/dt= 1.7580E-08 [mol/s] > > > -------------------------------------------------------------------------------------- > TRAN 1 Time= 3.17098E-08 Dt= 3.17098E-08 [y] snes_conv_reason: 3 > newton = 36 [ 36] linear = 36 [ 36] cuts = 0 [ 0] > --> max chng: dcmx= 5.0315E-08 dc/dt= 5.0315E-08 [mol/s] > > > 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. > > At the end i want to have a text file at the output producing this: > > 1 Time 3.17098E-08 Dt 3.17098E-08 newton 36 linear 36 cuts 0 > > > Id appreciate any hints, > ive just started python 2 days ago ))) > > thanks > > > > On 21 March 2013 14:24, James Boyd wrote: > > Hi Heidi, > > 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. > > I tried the code and works fine for me > > James > > On 21 Mar 2013, at 13:00, "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 > > _______________________________________________ > > Glasgow mailing list > > Glasgow at python.org > > http://mail.python.org/mailman/listinfo/glasgow > _______________________________________________ > Glasgow mailing list > Glasgow at python.org > http://mail.python.org/mailman/listinfo/glasgow > > > > > _______________________________________________ > Glasgow mailing list > Glasgow at python.org > http://mail.python.org/mailman/listinfo/glasgow > > > > _______________________________________________ > Glasgow mailing list > Glasgow at python.org > http://mail.python.org/mailman/listinfo/glasgow > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From dougal85 at gmail.com Mon Mar 25 13:40:30 2013 From: dougal85 at gmail.com (Dougal Matthews) Date: Mon, 25 Mar 2013 12:40:30 +0000 Subject: [Python Glasgow] How to write lines that start with TRAN to another output file In-Reply-To: References: <2C379F859C29430F9EE8AE31679D9914@gmail.com> Message-ID: <0DC5893C56224EAAB54CF6D2247A52DE@gmail.com> You can also use relative paths "data/something.txt" will access the files in the data directory relative to the python file you run. To create files, you need to look at the different file opening modes. They are described here: http://docs.python.org/2/library/functions.html#open - currently you are using one mode "a" for your output - you might want to choose one of the others. Dougal On Monday, 25 March 2013 at 12:36, Hedieh Ebrahimi wrote: > Thanks Dougal, but one question, the full path works if I am working on this computer and with this user. > > Is there anyway I could set this if i am planning to run the code on another system? > > Also I am getting output to an output.txt file which I have already created. > Is there anyway to ask python to create a text file ? > > I checked python File I\O but I couldnt find anything on creating files. > > Id appreciate any help > > Thanks > > > > On 25 March 2013 12:32, Dougal Matthews wrote: > > You just need to use the full path to the file - for example; > > > > open('/path/to/file/p.txt') > > > > If your on windows that will likely that with c:// etc. > > > > > > On Monday, 25 March 2013 at 11:28, Hedieh Ebrahimi wrote: > > > > > Hi all, > > > > > > I am getting an input file and then im writing to an output file. > > > > > > Right now they are both in the current working directory. > > > > > > 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? > > > > > > Thanks for help > > > > > > Hedie > > > > > > > > > On 21 March 2013 18:01, Hedieh Ebrahimi wrote: > > > > #! /usr/bin/python > > > > > > > > # Python Program to read a text file, edit it and give a text file as output > > > > > > > > > > > > > > > > #print("Python is really a great language,", "isnt it?"); > > > > #searchquery='TRAN' > > > > > > > > > > > > > > > > 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()) > > > > ###columns = line.split() > > > > > > > > #with open('Output.txt', 'a') as f2: > > > > #f=open('Output.txt') > > > > with open('Output.txt') as f2: > > > > with open('Output2.txt') as f3: > > > > s=f2.readlines() > > > > str1 = ''.join(s) > > > > str1.split() > > > > print(str1) > > > > #f3.write(str1) > > > > #print('Split this Sentence'.split()) > > > > #with open('Output2.txt') as f3: > > > > > > > > > > > > > > > > On 21 March 2013 15:44, Hedieh Ebrahimi wrote: > > > > > Thanks guys for help with previous question. its working now. > > > > > > > > > > I have another question. I need to extract information. so i now have a file like this : > > > > > > > > > > TRAN 1 Time= 3.17098E-08 Dt= 3.17098E-08 [y] snes_conv_reason: 3 > > > > > newton = 36 [ 36] linear = 36 [ 36] cuts = 0 [ 0] > > > > > --> max chng: dcmx= 5.0315E-08 dc/dt= 5.0315E-08 [mol/s] > > > > > TRAN 2 Time= 6.34196E-08 Dt= 3.17098E-08 [y] snes_conv_reason: 3 > > > > > newton = 4 [ 40] linear = 4 [ 40] cuts = 0 [ 0] > > > > > --> max chng: dcmx= 3.0785E-08 dc/dt= 3.0785E-08 [mol/s] > > > > > TRAN 3 Time= 1.26839E-07 Dt= 6.34196E-08 [y] snes_conv_reason: 3 > > > > > newton = 4 [ 44] linear = 4 [ 44] cuts = 0 [ 0] > > > > > --> max chng: dcmx= 3.5161E-08 dc/dt= 1.7580E-08 [mol/s] > > > > > > > > > > -------------------------------------------------------------------------------------- > > > > > TRAN 1 Time= 3.17098E-08 Dt= 3.17098E-08 [y] snes_conv_reason: 3 > > > > > newton = 36 [ 36] linear = 36 [ 36] cuts = 0 [ 0] > > > > > --> max chng: dcmx= 5.0315E-08 dc/dt= 5.0315E-08 [mol/s] > > > > > > > > > > > > > > > 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. > > > > > > > > > > At the end i want to have a text file at the output producing this: > > > > > > > > > > 1 Time 3.17098E-08 Dt 3.17098E-08 newton 36 linear 36 cuts 0 > > > > > > > > > > > > > > > Id appreciate any hints, > > > > > ive just started python 2 days ago ))) > > > > > > > > > > thanks > > > > > > > > > > > > > > > > > > > > On 21 March 2013 14:24, James Boyd wrote: > > > > > > Hi Heidi, > > > > > > > > > > > > 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. > > > > > > > > > > > > I tried the code and works fine for me > > > > > > > > > > > > James > > > > > > > > > > > > On 21 Mar 2013, at 13:00, "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 > > > > > > > _______________________________________________ > > > > > > > Glasgow mailing list > > > > > > > Glasgow at python.org (mailto:Glasgow at python.org) > > > > > > > http://mail.python.org/mailman/listinfo/glasgow > > > > > > _______________________________________________ > > > > > > Glasgow mailing list > > > > > > Glasgow at python.org (mailto:Glasgow at python.org) > > > > > > http://mail.python.org/mailman/listinfo/glasgow > > > > > > > > > > > > > > > _______________________________________________ > > > Glasgow mailing list > > > Glasgow at python.org (mailto:Glasgow at python.org) > > > http://mail.python.org/mailman/listinfo/glasgow > > > > > > > > > > > > > > > > > _______________________________________________ > > Glasgow mailing list > > Glasgow at python.org (mailto:Glasgow at python.org) > > http://mail.python.org/mailman/listinfo/glasgow > > > > _______________________________________________ > Glasgow mailing list > Glasgow at python.org (mailto:Glasgow at python.org) > http://mail.python.org/mailman/listinfo/glasgow > > -------------- next part -------------- An HTML attachment was scrubbed... URL: