Re: Line indexing in Python

2009-12-22 Thread MRAB
Lie Ryan wrote: On 12/22/2009 11:25 PM, Steve Holden wrote: > > If you want to extract an index number from the first part of of a given > line use split( split_character, maximum_splits_to_do ) and then angle > brackets to reference the first part (index 0)... > > a = "20 GOTO 10"

Re: Line indexing in Python

2009-12-22 Thread r0g
Steve Holden wrote: > r0g wrote: >> seafoid wrote: >>> Hi Guys, >>> >>> When python reads in a file, can lines be referred to via an index? >>> >>> Example: >>> >>> for line in file: >>> if line[0] == '0': >>> a.write(line) >>> >>> This works, however, I am unsure if line[0] refers on

Re: Line indexing in Python

2009-12-22 Thread Lie Ryan
On 12/22/2009 11:25 PM, Steve Holden wrote: > > If you want to extract an index number from the first part of of a given > line use split( split_character, maximum_splits_to_do ) and then angle > brackets to reference the first part (index 0)... > > a = "20 GOTO 10" int( a.split('

Re: Line indexing in Python

2009-12-22 Thread Steve Holden
r0g wrote: > seafoid wrote: >> Hi Guys, >> >> When python reads in a file, can lines be referred to via an index? >> >> Example: >> >> for line in file: >> if line[0] == '0': >> a.write(line) >> >> This works, however, I am unsure if line[0] refers only to the first line or >> the fir

Re: Line indexing in Python

2009-12-21 Thread r0g
seafoid wrote: > Hi Guys, > > When python reads in a file, can lines be referred to via an index? > > Example: > > for line in file: > if line[0] == '0': > a.write(line) > > This works, however, I am unsure if line[0] refers only to the first line or > the first character in all l

Re: Line indexing in Python

2009-12-18 Thread seafoid
ding them > up or comparing them to the header attributes > > -- > Rory Campbell-Lange > Director > r...@campbell-lange.net > > Campbell-Lange Workshop > www.campbell-lange.net > 0207 6311 555 > 3 Tottenham Street London W1T 2AF > Registered in E

Re: Line indexing in Python

2009-12-18 Thread seafoid
o assign variables within a loop! Is there an easy way to 'flatten' a nested list and assign the lists to variables? Thanks, Seafoid. -- View this message in context: http://old.nabble.com/Line-indexing-in-Python-tp26845253p26849921.html Sent from the Python - python-list mailing list archive at Nabble.com. -- http://mail.python.org/mailman/listinfo/python-list

Re: Line indexing in Python

2009-12-18 Thread Rory Campbell-Lange
On 18/12/09, seafoid (fitzp...@tcd.ie) wrote: > http://old.nabble.com/Parsing-file-format-to-ensure-file-meets-criteria-to26837682.html Your specification is confusing. However I suggest you break it down the code so that the steps in your programme are logical. Good luck. # example psuedocode he

Re: Line indexing in Python

2009-12-18 Thread Rory Campbell-Lange
On 18/12/09, seafoid (fitzp...@tcd.ie) wrote: > Have you any suggestions how I may render this code undead or should I scrap > it and create something new? It might be easier for us to help you if you give us an example of your input file and a clearer description of what you are trying to do with

Re: Line indexing in Python

2009-12-18 Thread seafoid
r being a > single letter that you know? > > Thanks in advance, > Seafoid. > -- View this message in context: http://old.nabble.com/Line-indexing-in-Python-tp26845253p26847598.html Sent from the Python - python-list mailing list archive at Nabble.com. -- http://mail.python.org/mailman/listinfo/python-list

Re: Line indexing in Python

2009-12-18 Thread Lie Ryan
On 12/19/2009 4:33 AM, seafoid wrote: Thanks for that Lie. I had to have a think about what you meant when you referred to control going to a.write(line). and if-elif-elif-... chain is executed sequentially and when a match is found, the rest of the chain is skipped. Your code: if line.sta

Re: Line indexing in Python

2009-12-18 Thread seafoid
biologist :-( Thanks, Seafoid. -- View this message in context: http://old.nabble.com/Line-indexing-in-Python-tp26845253p26846854.html Sent from the Python - python-list mailing list archive at Nabble.com. -- http://mail.python.org/mailman/listinfo/python-list

Re: Line indexing in Python

2009-12-18 Thread Lie Ryan
On 12/19/2009 3:27 AM, seafoid wrote: Thanks for that Richard and Steve. I have another question. What's the question? fname = raw_input('Please enter the name of the file: ') # create file objects blah = open(fname, 'r') a = open('rubbish', 'w') for line in blah: if line.startswith

Re: Line indexing in Python

2009-12-18 Thread seafoid
this message in context: http://old.nabble.com/Line-indexing-in-Python-tp26845253p26846049.html Sent from the Python - python-list mailing list archive at Nabble.com. -- http://mail.python.org/mailman/listinfo/python-list

Re: Line indexing in Python

2009-12-18 Thread seafoid
ero, assign lines to lists. Any suggestions? Seafoid. -- View this message in context: http://old.nabble.com/Line-indexing-in-Python-tp26845253p26845949.html Sent from the Python - python-list mailing list archive at Nabble.com. -- http://mail.python.org/mailman/listinfo/python-list

Re: Line indexing in Python

2009-12-18 Thread Steve Holden
seafoid wrote: > Hi Guys, > > When python reads in a file, can lines be referred to via an index? > > Example: > > for line in file: > if line[0] == '0': > a.write(line) > > This works, however, I am unsure if line[0] refers only to the first line or > the first character in all l

Re: Line indexing in Python

2009-12-18 Thread Richard Thomas
efers only to the first line or > the first character in all lines. > > Is there an easy way to refer to a line with the first character being a > single letter that you know? > > Thanks in advance, > Seafoid. > -- > View this message in > context:http://old.nabble.co

Line indexing in Python

2009-12-18 Thread seafoid
y to refer to a line with the first character being a single letter that you know? Thanks in advance, Seafoid. -- View this message in context: http://old.nabble.com/Line-indexing-in-Python-tp26845253p26845253.html Sent from the Python - python-list mailing list archive at Nabble.com.