LoginSignup
5
5

More than 5 years have passed since last update.

Pythonインタプリタのプロンプト変更

Posted at

おはようございます(徹夜):whale2:
Python入門時からスクリプトはファイルに書いていたため、使ったことがなかったインタプリタをさわっています。

インタプリタの起動
$ python
Python 3.5.1 |Anaconda 4.1.0 (x86_64)| (default, Jun 15 2016, 16:14:02)
[GCC 4.2.1 Compatible Apple LLVM 4.2 (clang-425.0.28)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
超かんたんな操作
>>> a = (
... 2,3,5,7
... )
>>> print(a)
(2, 3, 5, 7)
>>> exit()

Pythonインタプリタのプロンプト文字列はsysモジュールから得られます。

プロンプト文字列確認
>>> import sys
>>> sys.ps1
'>>> '
>>> sys.ps2
'... '
>>> exit()

インタプリタの一次プロンプト(PS1)は「>>> 」、二次プロンプト(PS2)は「... 」になっていることがわかりました。

プロンプトを変更してみる
>>> import sys
>>> sys.ps2 = '(๑•̀ㅂ•́)و '
>>> sys.ps1 = '(๑˃̵ᴗ˂̵)و '
(๑˃̵ᴗ˂̵)و '''
(๑•̀ㅂ•́)و インタプリタの
(๑•̀ㅂ•́)و 女子力が
(๑•̀ㅂ•́)و あがった!
(๑•̀ㅂ•́)و '''
'\nインタプリタの\n女子力が\nあがった!\n'
(๑˃̵ᴗ˂̵)و exit()

おわりです

(๑˃̵ᴗ˂̵)و✧

参考と注釈

5
5
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
5
5