python小技巧

dir查看对象的属性

>>> dir(re)
['DEBUG', 'DOTALL', 'I', ...'compile'....]

help查看模块方法的使用

>>>help('compile')


命令行自动补全
cat ~/.pythonstartup 
# python startup file
import readline
import rlcompleter
import atexit
import os
# 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

vi /etc/profile
export PYTHONSTARTUP=/root/.pythonstartup
source /etc/profile


本博客所有文章除特别声明外,均采用 CC BY-SA 4.0 协议 ,转载请注明出处!