2017-10-06 2 views
0
sample_text = ''' 
     The textwrap module can be used to format text for output in 
     situations where pretty-printing is desired. It offers 
     programmatic functionality similar to the paragraph wrapping 
     or filling features found in many text editors. 
    ''' 
dedented_text = textwrap.dedent(sample_text) 
wrapped = textwrap.fill(dedented_text, width=50) 
final = textwrap.indent(wrapped, '> ') 

print('Quoted block:\n') 
print(final) 

출력 인 경우 : 여분의 공간을 사용 textwrap.indent는()

> The textwrap module can be used to format text 
> for output in situations where pretty-printing is 
> desired. It offers programmatic functionality 
> similar to the paragraph wrapping or filling 
> features found in many text editors. 

그냥 처음에 첫 번째 줄에 여분의 공간이 이유를 이해하려고?

'\n  The textwrap module can be used to format text for output in\n  situations where pretty-printing is desired. It offers\n  programmatic functionality similar to the paragraph wrapping\n  or filling features found in many text editors.\n ' 

주의 시작 부분에 \n :

답변

2

repr(sample_text)에서보세요?

원하는 출력을 얻으려면, 그것을 벗어나야합니다. 문자열 시작 부분에 을 넣으십시오.

sample_text = '''\ 
    The textwrap module can be used to format text for output in 
    situations where pretty-printing is desired. It offers 
    programmatic functionality similar to the paragraph wrapping 
    or filling features found in many text editors. 
''' 
+0

작성하셨습니다! 감사!! –

관련 문제