print odd numbers of lines from tekst WITHOUT space between lines

breamoreboy at gmail.com breamoreboy at gmail.com
Sat Feb 18 14:50:52 EST 2017


On Saturday, February 18, 2017 at 6:03:37 PM UTC, Wildman wrote:
> On Sat, 18 Feb 2017 09:38:32 -0800, TTaglo wrote:
> 
> > i = 1
> > f = open ('rosalind_ini5(1).txt')
> > for line in f.readlines():
> >     if i % 2 == 0:
> >         print line
> >     i += 1
> > 
> > 
> > How do i get output without breaks between the lines?
> > 
> > Result:
> > 
> > Other things just make you swear and curse
> > 
> > When you're chewing on life's gristle, don't grumble give a whistle
> > 
> > This will help things turn out for the best
> > 
> > Always look on the bright side of life
> 
> In Python 3 you can do this:
> 
> print(line, end="")
> 
> For Python 2 use this:
> 
> import sys
>   .
>   .
>   .
> sys.stdout.write(line)
> 
> Don' forget...
> f.close()
> 
> -- 
> <Wildman> GNU/Linux user #557453
> The cow died so I don't need your bull!

For Python 2, strictly from memory:-

from __future__ import print_function

print(line, end="")

Kindest regards.

Mark Lawrence.



More information about the Python-list mailing list