[Tutor] Getting range of a list
Dave Angel
davea at davea.name
Tue Feb 5 23:20:39 CET 2013
On 02/05/2013 04:48 PM, Hs Hs wrote:
> Thanks Steve.
>
> But one question, when I print, I get extra empty lines. How to get rid of them! Thanks again.
>>>> f = open('test')
>>>> head = '---'
>>>> for line in f:
line = line.rstrip() #get rid of the trailing newline (and any other
whitespace there)
> if line.startswith('>'):
> head = line[1:].strip()
> else:
> print head+'\t'+line
The print generates a newline by default. So you either have to do the
strip() I suggested above, or use a trailing comma on the print. I
recommend the former.
>
> X1A
> <------
> X1G
> <-----
> X2A
>
> X2G
>
> X3A
>
> X3G
>
> X4A
>
> X4A
>
> Thanks
> Hs.
>
>
>
You're still posting using html mail. And your indentation is still
getting messed up. Also, you top-posted.
--
DaveA
More information about the Tutor
mailing list