bokr at oz.net
Mon Sep 16 21:50:53 CEST 2002
On 11 Sep 2002 18:27:48 +0300, Erno Kuusela <erno-news at erno.iki.fi> wrote:
>In article <mailman.1031684894.10361.python-list at python.org>,
>jubafre at brturbo.com writes:
>| I have a file with assembler instruction and i want read the lines
>| of the file and put in a list of string, this is easy to do, but i
>| don´t want to consider the caracteres "/" and the othes after him.
>| ADD D1 /coment1
>| LDA D2 /coment2
>try something like...
> out = 
> for line in open(filename).readlines():
out.append(line.split('/').rstrip()) # so as to get ['ADD D1', ...] not ['ADD D1 ', ...]
> return out
A nit ;-)
Alternatively, if you have 2.2,
>>> [x.split('/',1).rstrip() for x in file('file.asm')]
['ADD D1', 'LDA D2']
where the file is
['ADD D1 /coment1\n', 'LDA D2 /coment2']
Oops. Well, the missing final \n didn't hurt.
More information about the Python-list