标签:clear python命令行清屏 clear清屏 python清屏 python 命令行里实现clear清屏技巧
对于很多新手,当然我也是新手,在命令行里学习python的时候占满了屏幕,很不习惯,特别是使用linux习惯了,使用clear清屏,这样的感觉非常好,但是python下面没有这样的命令和功能,下面为了解决这个问题,本人写了个简单的模块
1 先来看下没有清屏的结果
[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. >>> >>> >>> >>> >>> >>> >>> >>> >>> >>> >>> >>> >>> >>>
这样特别让人厌恶,至少我有这样的感觉
2 解决办法
[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 设置环境变量
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() >>>
这里的效果贴出来不明显,大家动手试下,不懂的话可以在下面留言
本文出自 “游造技术博客” 博客,请务必保留此出处http://youzao.blog.51cto.com/3946111/1410921
python 命令行里实现clear清屏技巧,布布扣,bubuko.com
标签:clear python命令行清屏 clear清屏 python清屏 python 命令行里实现clear清屏技巧
原文地址:http://youzao.blog.51cto.com/3946111/1410921