LoginSignup
1
0

More than 3 years have passed since last update.

エスケープシークエンスで文字のタイプを変更する

Last updated at Posted at 2018-03-09

目的

カラフルな出力には\033[93mといった特殊文字が用いられる.
それらを全て暗記するのは困難であるので,一括で表示するコードを書いた.
筆者はalias colors='...'.bash_profileに追記することで呼び出せるようにしている.

環境

python
$ python
Python 3.6.4 |Anaconda custom (64-bit)| (default, Jan 16 2018, 12:04:33)
[GCC 4.2.1 Compatible Clang 4.0.1 (tags/RELEASE_401/final)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>

コード

color.py
#!/usr/bin/env python

for i in range(110):
    print(f'\033[{i}m' + '{0:3d}'.format(i) + '\033[0m', end = ' ')
    if str(i)[-1] == '9':
        print('\n')

実行

スクリーンショット 2018-03-09 21.51.45.png

おわり.

1
0
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
1
0