對於不少新手,固然我也是新手,在命令行裏學習python的時候佔滿了屏幕,很不習慣,特別是使用linux習慣了,使用clear清屏,這樣的感受很是好,可是python下面沒有這樣的命令和功能,下面爲了解決這個問題,本人寫了個簡單的模塊
python
1 先來看下沒有清屏的結果linux
[root@zh ~]# python Python 2.6.6 (r266:84292, Nov 22 2013, 12:11:10) [GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> >>> >>> >>> >>> >>> >>> >>> >>> >>> >>> >>> >>> >>>
這樣特別讓人厭惡,至少我有這樣的感受bash
2 解決辦法ide
[root@zh ~]# cat clear.py #!/usr/bin/python import os def clear(): os.system('clear')
3 爲了更使用方便,咱們不用每次都使用import導入學習
[root@zh ~]# cat startup.py #!/usr/bin/python # python startup file import sys import readline import rlcompleter import atexit import os import clear # tab completion readline.parse_and_bind('tab: complete') # history file histfile = os.path.join(os.environ['HOME'], '.pythonhistory') try: readline.read_history_file(histfile) except IOError: pass atexit.register(readline.write_history_file, histfile) del os, histfile, readline, rlcompleter
你們留意看下import clear 我上面這個腳本是python的tab功能測試
4 設置環境變量 spa
del os, histfile, readline, rlcompleter [root@zh ~]# cat .bashrc # .bashrc # User specific aliases and functions alias rm='rm -i' alias cp='cp -i' alias mv='mv -i' export PYTHONSTARTUP=/root/startup.py # Source global definitions if [ -f /etc/bashrc ]; then . /etc/bashrc fi [root@zh ~]# source .bashrc [root@zh ~]#
5 測試命令行
[root@zh ~]# python Python 2.6.6 (r266:84292, Nov 22 2013, 12:11:10) [GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> >>> >>> >>> >>> >>> >>> >>> >>> >>> >>> clear.clear() >>>
這裏的效果貼出來不明顯,你們動手試下,不懂的話能夠在下面留言orm