[Tutor] Getting range of a list
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
> if line.startswith('>'):
> head = line[1:].strip()
> 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.
You're still posting using html mail. And your indentation is still
getting messed up. Also, you top-posted.
More information about the Tutor