下载
第三方包安装方法
第一种方法(不使用pip或者easy_install):
Step1:在网上找到的需要的包,下载下来。eg. rsa-3.1.4.tar.gz
Step2:解压缩该文件。
Step3:命令行工具cd切换到所要安装的包的目录,找到setup.py
文件,然后输入python setup.py install
第二种方法(使用pip或者easy_install):
直接打开cmd,敲pip install rsa
。
多版本python共存,安装三方库到指定python版本
python3下pip安装命令如下:
py -3 -m pip install xxxxxx
python2下pip安装命令如下:
py -2 -m pip install xxxxxx
查询python3下三方库如下:
py -3 -m pip list
查询python2下三方库如下:
py -2 -m pip list
VS Code
An In Depth Tutorial on Linux Development on Windows with WSL and Visual Studio Code
https://code.visualstudio.com/updates/v1_36
安装python插件
打开VScode,Ctrl+p
输入 “ext install python”
##pycharm##
多线程
class myThread (threading.Thread):
def __init__(self, threadID, name, counter):
threading.Thread.__init__(self)
self.threadID = threadID
self.name = name
self.counter = counter
def run(self):
print("Starting " + self.name)
print_time(self.name, self.counter, 5)
print("Exiting " + self.name)
json
with open("../config/record.json",'r') as load_f:
load_dict = json.load(load_f)
print(load_dict)
load_dict['smallberg'] = [8200,{1:[['Python',81],['shirt',300]]}]
print(load_dict)
with open("../config/record.json","w") as dump_f:
json.dump(load_dict,dump_f)
jsonpath
https://goessner.net/articles/JsonPath/
logging
import os
import logging
import sys
import time
import logging.handlers
def singleton(cls):
instances = {}
def _singleton(*args,**kwargs):
if cls not in instances:
instances[cls] = cls(*args,**kwargs)
return instances[cls]
return _singleton
@singleton
class Logger():
def __init__(self,logfile=None):
self.logger = logging.getLogger()
formater = logging.Formatter('%(asctime)s %(name)s %(levelname)s %(filename)s %(lineno)d '
'%(thread)d %(threadName)s %(process)d %(message)s')
if logfile == None:
stime = time.strftime("%Y-%m-%d",time.localtime())
logfile = os.getcwd() + os.sep + "log_" + stime + ".log"
else:
logfile = os.path.join(os.getcwd(),logfile)+ ".log"
self.sh = logging.StreamHandler(sys.stdout)
self.sh.setFormatter(formater)
#self.fh = logging.FileHandler(logfile)
self.fh = logging.handlers.RotatingFileHandler(logfile, maxBytes = 1024*1024, backupCount = 5)
self.fh.setFormatter(formater)
self.logger.addHandler(self.sh)
self.logger.addHandler(self.fh)
self.logger.setLevel(logging.INFO)
if __name__ == "__main__":
lg = Logger("test")
lg.logger.warning("test")
WxPython
插件
https://www.aixcoder.com/#/downloaddjs
打包
pip install pyinstaller
pycharm下PyInstaller 打包 python程序
pychaim下PyInstaller 打包 python程序
pyinstaller -F -w -i json.ico MakeRule.py
-F:打包后只生成单个exe格式文件;
-D:默认选项,创建一个目录,包含exe文件以及大量依赖文件;
-c:默认选项,使用控制台(就是类似cmd的黑框);
-w:不使用控制台;
-p:添加搜索路径,让其找到对应的库;
-i:改变生成程序的icon图标。