fedora ~ $ python
Python 2.7.8 (default, Nov 10 2014, 08:19:18)
[GCC 4.9.2 20141101 (Red Hat 4.9.2-1)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys #导入sys模块 >>> sys.path #查看python环境变量 [‘‘, ‘/usr/lib64/python27.zip‘, ‘/usr/lib64/python2.7‘, ‘/usr/lib64/python2.7/plat-linux2‘, ‘/usr/lib64/python2.7/lib-tk‘, ‘/usr/lib64/python2.7/lib-old‘, ‘/usr/lib64/python2.7/lib-dynload‘, ‘/usr/lib64/python2.7/site-packages‘, ‘/usr/lib64/python2.7/site-packages/gtk-2.0‘, ‘/usr/lib/python2.7/site-packages‘]
环境变量中 搜索顺序 ‘’ 代表当前目录,会按照这个顺序来搜索你要的模块。
我的放在 /usr/lib64/python2.7/site-packages/ 这个目录
在指定的目录下面添加 tab.py (tab.py 是借的别人的)
/usr/lib64/python2.7/site-packages $sudo vim tab.py
#!/bin/env python import sys 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
导入tab模块
>>> import tab >>> import os >>> os. #已经支持tab功能了 Display all 249 possibilities? (y or n) os.EX_CANTCREAT os.ST_NOSUID os._spawnvef( os.getlogin( os.seteuid( os.EX_CONFIG os.ST_RDONLY os.abort( os.getpgid( os.setgid( os.EX_DATAERR os.ST_RELATIME os.access( os.getpgrp( os.setgroups( os.EX_IOERR os.ST_SYNCHRONOUS os.altsep os.getpid( os.setpgid(
可以调用shell命令
>>> os.system(‘ip r‘) default via 192.168.1.1 dev wlp3s0 proto static metric 1024 192.168.1.0/24 dev wlp3s0 proto kernel scope link src 192.168.1.120 192.168.122.0/24 dev virbr0 proto kernel scope link src 192.168.122.1
时间: 2024-12-14 22:53:10