LoginSignup
3
1

More than 5 years have passed since last update.

Python > textwrap > 文字列を指定の長さで区切る

Posted at
動作環境
GeForce GTX 1070 (8GB)
ASRock Z170M Pro4S [Intel Z170chipset]
Ubuntu 16.04 LTS desktop amd64
TensorFlow v1.2.1
cuDNN v5.1 for Linux
CUDA v8.0
Python 3.5.2
IPython 6.0.0 -- An enhanced Interactive Python.
gcc (Ubuntu 5.4.0-6ubuntu1~16.04.4) 5.4.0 20160609
GNU bash, version 4.3.48(1)-release (x86_64-pc-linux-gnu)
scipy v0.19.1
geopandas v0.3.0
MATLAB R2017b (Home Edition)
ADDA v.1.3b6

Jupyter Notebookにて長い文字列を表示した時、スクロールバーが表示される。
スクロールバーでなく、適当な長さで改行するには自作の関数を用意するか、textwrapを使う方法がある。

Jupyter code

import textwrap as tw

#1. prepare text
text = ''
for idx in range(200):
    text += '.'

#2. print    
print(text)

for elem in tw.wrap(text, width=80):
    print(elem)

qiita.png

ここで、水平スクロールバーはprint(text)により表示されている。

3
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1