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"
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
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('
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
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
Rory,
You are a gentleman!
Thank you very much for your suggestion!
Kind Regards,
Seafoid.
Rory Campbell-Lange wrote:
>
> 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 confus
Hey folks,
Is it possible to assign a list within a nested list to a variable?
Example:
l = [['1', '2', '3'], ['4', '5', '6']]
for i in l:
if i[0][1] == '1':
m = i
Indeed, I generally do not understand how to assign variables within a loop!
Is there an easy way to 'flatten' a nes
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
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
Hi Guys,
It has been point out that it is difficult for anyone to provide suggestions
if I do not outline more clearly my input file and an example of what I wish
to do with it (Thanks Rory!).
I mentioned it in this thread (Is creating different threads bad etiquette?
If so, lesson learned!):
h
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
Thanks for that Lie.
I had to have a think about what you meant when you referred to control
going to a.write(line).
Have you any suggestions how I may render this code undead or should I scrap
it and create something new?
My confusion and ineptitude is perhaps explained by my being a biologist
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
Thanks for that Richard and Steve!
Below is my full code so far:
for line in file:
if line.startswith("1"):
a.write(line)
elif line.endswith("0"):
lists_a = line.strip().split()
print lists_a
elif line.startswith("2"):
lists_b = line.strip().split()
Thanks for that Richard and Steve.
I have another 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("0"):
a.write(line)
elif line.endswith("0"):
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
On Dec 18, 3:42 pm, 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 c
17 matches
Mail list logo