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  -  [email protected]
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.

_______________________________________________
Tutor maillist  -  [email protected]
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to