日常python小命令
pip:
其中比较常见的:安装指定版本的软件
1 pip install package==version
如上pip 安装python软件包,如果你在网上下载的gz包的开源安装包,安装方法如下:以django为例子:
tar xzvf Django-*.tar.gz 。 cd Django-* 。 sudo python setup.py install 。
如何查看一个软件的源码呢?
比如查看ansible的源码:
1 >>> import ansible 2 >>> ansible.__file__ 3 '/usr/lib/python2.6/site-packages/ansible/__init__.pyc'
然后到目录:cd /usr/lib/python2.6/site-packages/ansible 查看相应的类中的__init__py既可。
1 [root@MiWiFi-R1CM-srv venv]# cd /usr/lib/python2.6/site-packages/ansible 2 [root@MiWiFi-R1CM-srv ansible]# pwd 3 /usr/lib/python2.6/site-packages/ansible 4 [root@MiWiFi-R1CM-srv ansible]# ls 5 cli config constants.pyc executor __init__.py inventory module_utils playbook release.py template vars 6 compat constants.py errors galaxy __init__.pyc modules parsing plugins release.pyc utils 7 [root@MiWiFi-R1CM-srv ansible]# cd playbook/ 8 [root@MiWiFi-R1CM-srv playbook]# ls 9 attribute.py block.py handler_task_include.py __init__.py play_context.py role_include.pyc task.pyc 10 attribute.pyc block.pyc handler_task_include.pyc __init__.pyc play_context.pyc taggable.py vars_file.py 11 base.py conditional.py helpers.py loop_control.py play.py taggable.pyc vars_file.pyc 12 base.pyc conditional.pyc helpers.pyc loop_control.pyc play.pyc task_include.py vars.py 13 become.py handler.py included_file.py playbook_include.py role task_include.pyc vars.pyc 14 become.pyc handler.pyc included_file.pyc playbook_include.pyc role_include.py task.py 15 [root@MiWiFi-R1CM-srv playbook]# cat __init__.py
或者直接安装ipython 来查看:
如何将python注册到window注册表中,如下是python3运行版本:
1 import sys 2 3 from winreg import * 4 5 # tweak as necessary 6 version = sys.version[:3] 7 installpath = sys.prefix 8 9 regpath = "SOFTWARE\\Python\\Pythoncore\\%s\\" % (version) 10 installkey = "InstallPath" 11 pythonkey = "PythonPath" 12 pythonpath = "%s;%s\\Lib\\;%s\\DLLs\\" % ( 13 installpath, installpath, installpath 14 ) 15 16 def RegisterPy(): 17 try: 18 reg = OpenKey(HKEY_CURRENT_USER, regpath) 19 except EnvironmentError as e: 20 try: 21 reg = CreateKey(HKEY_CURRENT_USER, regpath) 22 SetValue(reg, installkey, REG_SZ, installpath) 23 SetValue(reg, pythonkey, REG_SZ, pythonpath) 24 CloseKey(reg) 25 except: 26 print("*** Unable to register!") 27 return 28 print("--- Python", version, "is now registered!") 29 return 30 if (QueryValue(reg, installkey) == installpath and 31 QueryValue(reg, pythonkey) == pythonpath): 32 CloseKey(reg) 33 print("=== Python", version, "is already registered!") 34 return 35 CloseKey(reg) 36 print("*** Unable to register!") 37 print("*** You probably have another Python installation!") 38 39 if __name__ == "__main__": 40 RegisterPy()
在安装pyiwin32的时候就不会python3.5未安装。
python 在线查找内置模块和库地址:
python3:
1 https://docs.python.org/3/library/index.html
python2
1 https://docs.python.org/2/library/index.html
学习是一种态度,坚持是质变的利器!

浙公网安备 33010602011771号