[Tutor] inserting new lines in long strings while printing
Mark Lawrence
breamoreboy at yahoo.co.uk
Wed Mar 7 02:36:40 CET 2012
On 07/03/2012 01:26, Abhishek Pratap wrote:
> I have this one big string in python which I want to print to a file
> inserting a new line after each 100 characters. Is there a slick way to do
> this without looping over the string. I am pretty sure there shud be
> something its just I am new to the lang.
>
>
> Thanks!
> -Abhi
>
>
>
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
Simplest way I can think of (untested).
onebigstring = 'nbgkasgf;sh;slfgh;asdgh;adsdhg fg...'
for i in range(0, len(onebigstring), 100): # for Python3, xrange for
Python 2
print onebigstring[i:i+100]
--
Cheers.
Mark Lawrence.
More information about the Tutor
mailing list