लचीला के लिए विकल्प, आप मानक पुस्तकालय में textwrap पर एक नज़र डालना चाहते हैं।
उदाहरण:
>>> hamlet='''\
... To be, or not to be: that is the question:
... Whether 'tis nobler in the mind to suffer
... The slings and arrows of outrageous fortune,
... Or to take arms against a sea of troubles,
... And by opposing end them? To die: to sleep;
... No more; and by a sleep to say we end
... '''
>>> import textwrap
>>> wrapper=textwrap.TextWrapper(initial_indent='\t', subsequent_indent='\t'*2)
>>> print wrapper.fill(hamlet)
To be, or not to be: that is the question: Whether 'tis nobler in the
mind to suffer The slings and arrows of outrageous fortune, Or to
take arms against a sea of troubles, And by opposing end them? To
die: to sleep; No more; and by a sleep to say we end
आप देख सकते हैं कि आप न केवल आसानी से एक लाइन के सामने पर लचीला अंतरिक्ष में जोड़ सकते हैं, तो आप फिट करने के लिए, hyphenate, आदि प्रत्येक पंक्ति ट्रिम कर सकते हैं टैब का विस्तार,
यह (इसलिए नाम) लाइनों है कि बहुत लंबा है क्योंकि मोर्चे पर अतिरिक्त की बन लपेटो जाएगा:
>>> wrapper=textwrap.TextWrapper(initial_indent='\t'*3,
... subsequent_indent='\t'*4, width=40)
>>> print wrapper.fill(hamlet)
To be, or not to be: that is the
question: Whether 'tis nobler in the
mind to suffer The slings and arrows
of outrageous fortune, Or to take
arms against a sea of troubles, And
by opposing end them? To die: to
sleep; No more; and by a sleep to
say we end
बहुत लचीला और उपयोगी।
संपादित
आप textwrap के साथ पाठ में लाइन अंत का मतलब रखने के लिए, बस splitlines साथ textwrap गठबंधन लाइन रखने के लिए एक ही अंत चाहते हैं।
फांसी मांगपत्र का उदाहरण:
import textwrap
hamlet='''\
Hamlet: In the secret parts of Fortune? O, most true! She is a strumpet. What's the news?
Rosencrantz: None, my lord, but that the world's grown honest.
Hamlet: Then is doomsday near.'''
wrapper=textwrap.TextWrapper(initial_indent='\t'*1,
subsequent_indent='\t'*3,
width=30)
for para in hamlet.splitlines():
print wrapper.fill(para)
print
प्रिंट
Hamlet: In the secret parts
of Fortune? O, most true!
She is a strumpet. What's
the news?
Rosencrantz: None, my lord,
but that the world's grown
honest.
Hamlet: Then is doomsday
near.
मुझे नहीं पता था कि, धन्यवाद! – JeromeJ