一些Python脚本


1. Python导入模块的三种方式:

import modulename
from module import xx
import moduleName as newName



2. Python命令行自动补全和记录历史命令

    [root@mm_local ~]# echo "export PYTHONSTARTUP='/root/.pythonstartup'" >> /root/.bashrc   
    [root@mm_local ~]# source /root/.bashrc  
    [root@mm_local ~]# cat /root/.pythonstartup   
    import os  
    import readline  
    import rlcompleter  
    import atexit  
      
      
    #tab completion  
    readline.parse_and_bind("tab: complete")  
      
      
    #history file  
    history_file = os.path.join(os.environ["HOME"],".pythonhistory")  
    try:  
        readline.read_history_file(history_file)  
    except IOError:  
        pass  
    atexit.register(readline.write_history_file,history_file)  
      
      
    del os,history_file,readline,rlcompleter  
    [root@mm_local ~]# python  
    Python 2.7.3 (default, Jun  5 2013, 22:40:26)   
    [GCC 4.4.6 20110731 (Red Hat 4.4.6-3)] on linux2  
    Type "help", "copyright", "credits" or "license" for more information.  
    >>> import sys  
    >>> sys.path #按tab键就可以自动补全了  
      
    [root@mm_local ~]# python  
    >>>  
    >>> sys.path #按上下方向键即可找到历史命令  


你可能感兴趣的:(Python)