1. \u5feb\u901f\u5171\u4eab<\/strong><\/span><\/div>\nHTTP\u670d\u52a1\u5668<\/p>\n
SimpleHTTPServer\u662fpython\u5185\u7f6e\u7684web\u670d\u52a1\u5668\uff0c\u4f7f\u75288000\u7aef\u53e3\u548cHTTP\u534f\u8bae\u5171\u4eab\u3002<\/p>\n
\u80fd\u591f\u5728\u4efb\u610f\u5e73\u53f0(Window\uff0cLinux\uff0cMacOS)\u5feb\u901f\u642d\u5efa\u4e00\u4e2aHTTP\u670d\u52a1\u548c\u5171\u4eab\u670d\u52a1\uff0c\u53ea\u9700\u8981\u642d\u5efa\u597dpython\u73af\u5883\u3002<\/p>\n
python2\u7248\u672c\uff1a<\/p>\n
python -m SimpleHTTPServer \r\n<\/pre>\npython3\u7248\u672c\uff1a<\/p>\n
python -m http.server\r\n<\/pre>\nFTP\u670d\u52a1\u5668
\nftp\u5171\u4eab\u9700\u8981\u7b2c\u4e09\u65b9\u7ec4\u4ef6\u652f\u6301\uff0c\u5b89\u88c5\u547d\u4ee4\uff1a<\/p>\n
pip install pyftpdlib \r\npython -m pyftpdlib-p\u7aef\u53e3\u53f7 \r\n\u8bbf\u95ee\u65b9\u5f0f\uff1aftp:\/\/IP:\u7aef\u53e3\u3002\r\n<\/pre>\n2. \u89e3\u538b\u7f29<\/strong><\/span><\/div>\n\u8fd9\u91cc\u4ecb\u7ecd\u5229\u7528python\u89e3\u538b\u4e94\u79cd\u538b\u7f29\u6587\u4ef6\uff1a.gz .tar .zip .rar
\nzip<\/p>\n
import zipfile \r\n# zipfile\u538b\u7f29 \r\nz = zipfile.ZipFile('x.zip', 'w', zipfile.ZIP_STORED) #\u6253\u5305\uff0czipfile.ZIP_STORED\u662f\u9ed8\u8ba4\u53c2\u6570 \r\n# z = zipfile.ZipFile('ss.zip', 'w', zipfile.ZIP_DEFLATED) #\u538b\u7f29 \r\nz.write('x2') \r\nz.write('x1') \r\nz.close() \r\n#zipfile\u89e3\u538b \r\nz = zipfile.ZipFile('x.zip', 'r') \r\nz.extractall(path=r\"C:UsersAdministratorDesktop\") \r\nz.close() \r\n<\/pre>\ntar<\/p>\n
import tarfile \r\n# \u538b\u7f29 \r\ntar = tarfile.open('your.tar', 'w') \r\ntar.add('\/Users\/wupeiqi\/PycharmProjects\/bbs2.log', arcname='bbs2.log') \r\ntar.add('\/Users\/wupeiqi\/PycharmProjects\/cmdb.log', arcname='cmdb.log') \r\ntar.close() \r\n# \u89e3\u538b \r\ntar = tarfile.open('your.tar', 'r') \r\ntar.extractall() # \u53ef\u8bbe\u7f6e\u89e3\u538b\u5730\u5740 \r\ntar.close() \r\n<\/pre>\ngz
\ngz\u4e00\u822c\u4ec5\u4ec5\u538b\u7f29\u4e00\u4e2a\u6587\u4ef6\uff0c\u5168\u90e8\u5e38\u4e0e\u5176\u5b83\u6253\u5305\u5de5\u5177\u4e00\u8d77\u5de5\u4f5c\u3002\u6bd4\u65b9\u80fd\u591f\u5148\u7528tar\u6253\u5305\u4e3aX.tar,\u7136\u540e\u5728\u538b\u7f29\u4e3aX.tar.gz
\n\u89e3\u538bgz\uff0c\u4e8b\u5b9e\u4e0a\u5c31\u662f\u8bfb\u51fa\u5f53\u4e2d\u7684\u5355\u4e00\u6587\u4ef6\uff0cPython\u65b9\u6cd5\u4f8b\u5982\u4ee5\u4e0b\uff1a<\/p>\n
import gzip \r\nimport os \r\ndef un_gz(file_name): \r\n\"\"\"ungz zip file\"\"\" \r\n f_name = file_name.replace(\".gz\", \"\") \r\n#\u83b7\u53d6\u6587\u4ef6\u7684\u540d\u79f0\uff0c\u53bb\u6389 \r\ng_file = gzip.GzipFile(file_name) \r\n#\u521b\u5efagzip\u5bf9\u8c61 \r\nopen(f_name, \"w+\").write(g_file.read()) \r\n#gzip\u5bf9\u8c61\u7528read()\u6253\u5f00\u540e\uff0c\u5199\u5165open()\u5efa\u7acb\u7684\u6587\u4ef6\u91cc\u3002 \r\ng_file.close() \r\n#\u5173\u95edgzip\u5bf9\u8c61 \r\n<\/pre>\nrar
\n\u7531\u4e8erar\u901a\u5e38\u4e3awindow\u4e0b\u4f7f\u7528\uff0c\u987b\u8981\u989d\u5916\u7684Python\u5305rarfile\u3002
\n\u5b89\u88c5\uff1a<\/p>\n
Python setup.py install \r\n<\/pre>\n\u89e3\u538b\u7f29\uff1a<\/p>\n
import rarfile \r\nimport os \r\ndef un_rar(file_name): \r\n\"\"\"unrar zip file\"\"\" \r\n rar = rarfile.RarFile(file_name) \r\nif os.path.isdir(file_name + \"_files\"): \r\npass \r\nelse: \r\n os.mkdir(file_name + \"_files\") \r\n os.chdir(file_name + \"_files\"): \r\n rar.extractall() \r\n rar.close() \r\n<\/pre>\n3.pip\u5e38\u7528\u64cd\u4f5c<\/strong><\/span><\/div>\npip \u662f Python \u8457\u540d\u7684\u5305\u7ba1\u7406\u5de5\u5177\uff0c\u5728 Python \u5f00\u53d1\u4e2d\u5fc5\u4e0d\u53ef\u5c11\u3002
\n\u5b89\u88c5
\n\u5728\u7ebf\u5b89\u88c5<\/p>\n
pip install < \u5305\u540d> \u6216 pip install -r requirements.txt \r\n<\/pre>\n\u672c\u5730\u5b89\u88c5\uff1a<\/p>\n
pip install < \u76ee\u5f55>\/< \u6587\u4ef6\u540d> \u6216 pip install --use-wheel --no-index --find-links=wheelhouse\/ < \u5305\u540d> \r\n<\/pre>\n\u67e5\u627e\u5305<\/p>\n
pip search < \u5305\u540d> \r\n<\/pre>\n\u5220\u9664\u5305<\/p>\n
pip uninstall < \u5305\u540d> \u6216 pip uninstall -r requirements.txt \r\n<\/pre>\n\u67e5\u770b\u5305\u4fe1\u606f<\/p>\n
pip show < \u5305\u540d> \r\n<\/pre>\n\u68c0\u67e5\u5305\u4f9d\u8d56\u662f\u5426\u5b8c\u6574<\/p>\n
pip check < \u5305\u540d> \r\n<\/pre>\n\u67e5\u770b\u5df2\u5b89\u88c5\u5305\u5217\u8868<\/p>\n
pip list \r\n<\/pre>\n\u5bfc\u51fa\u6240\u6709\u5df2\u5b89\u88c5\u5305<\/p>\n
pip freeze requirements.txt \r\n<\/pre>\n4. \u5b57\u7b26\u4e32\u4e0eJson\u8f6c\u6362<\/strong><\/span><\/div>\njson\u8f6cstr<\/p>\n
import json \r\nstr = '{\"name\": \"zyl\", \"age\": \"two\"}' \r\np = json.loads(str) \r\nprint(p) \r\nprint(type(p)) \r\n<\/pre>\njson\u8f6cstr
\n\u4f7f\u7528json.dumps\u7684\u65b9\u6cd5\uff0c\u53ef\u4ee5\u5c06json\u5bf9\u8c61\u8f6c\u5316\u4e3a\u5b57\u7b26\u4e32\u3002<\/p>\n
s = {'name':'zyl','age':'22'} \r\ns = json.dumps(s) <\/pre>\n5. python\u8bfb\u53d6excel<\/strong><\/span><\/div>\n\u6b65\u9aa4
\n\u5b89\u88c5python\u5b98\u65b9Excel\u5e93\u2013>xlrd
\n\u83b7\u53d6Excel\u6587\u4ef6\u4f4d\u7f6e\u5e76\u8bfb\u53d6
\n\u8bfb\u53d6sheet
\n\u8bfb\u53d6\u6307\u5b9arows\u548ccols\u5185\u5bb9
\n\u793a\u4f8b<\/p>\n
# -*- coding: utf-8 -*- \r\nimport xlrd \r\nfrom datetime import date,datetime \r\ndef read_excel(): \r\n#\u6587\u4ef6\u4f4d\u7f6e \r\nExcelFile=xlrd.open_workbook(r'C:UsersAdministratorDesktopTestData.xlsx') \r\n#\u83b7\u53d6\u76ee\u6807EXCEL\u6587\u4ef6sheet\u540d \r\nprint ExcelFile.sheet_names() \r\n#\u82e5\u6709\u591a\u4e2asheet\uff0c\u5219\u9700\u8981\u6307\u5b9a\u8bfb\u53d6\u76ee\u6807sheet\u4f8b\u5982\u8bfb\u53d6sheet2 \r\n#sheet2_name=ExcelFile.sheet_names()[1] \r\n#\u83b7\u53d6sheet\u5185\u5bb9\u30101.\u6839\u636esheet\u7d22\u5f152.\u6839\u636esheet\u540d\u79f0\u3011 \r\n#sheet=ExcelFile.sheet_by_index(1) \r\nsheet=ExcelFile.sheet_by_name('TestCase002') \r\n#\u6253\u5370sheet\u7684\u540d\u79f0\uff0c\u884c\u6570\uff0c\u5217\u6570 \r\nprint sheet.name,sheet.nrows,sheet.ncols \r\n#\u83b7\u53d6\u6574\u884c\u6216\u8005\u6574\u5217\u7684\u503c \r\nrows=sheet.row_values(2)#\u7b2c\u4e09\u884c\u5185\u5bb9 \r\ncols=sheet.col_values(1)#\u7b2c\u4e8c\u5217\u5185\u5bb9 \r\nprint cols,rows \r\n#\u83b7\u53d6\u5355\u5143\u683c\u5185\u5bb9 \r\nprint sheet.cell(1,0).value.encode('utf-8') \r\nprint sheet.cell_value(1,0).encode('utf-8') \r\nprint sheet.row(1)[0].value.encode('utf-8') \r\n#\u6253\u5370\u5355\u5143\u683c\u5185\u5bb9\u683c\u5f0f \r\nprint sheet.cell(1,0).ctype \r\nif__name__ =='__main__': \r\nread_excel() \r\n<\/pre>\n6. python \u622a\u56fe<\/strong><\/span><\/div>\npython\u5b9e\u73b0\u622a\u56fe\u529f\u80fd,windows\u73af\u5883\u4e0b,\u9700\u8981\u7528\u5230PIL\u5e93\u3002
\n\u5b89\u88c5\uff1a<\/p>\n
pip install Pillow \r\n<\/pre>\n\u793a\u4f8b\uff1a<\/p>\n
from PIL import ImageGrab \r\nbbox = (x1, y1, x2,y2 ) \r\n# x1: \u5f00\u59cb\u622a\u56fe\u7684x\u5750\u6807;x2:\u5f00\u59cb\u622a\u56fe\u7684y\u5750\u6807;x3:\u7ed3\u675f\u622a\u56fe\u7684x\u5750\u6807;x4:\u7ed3\u675f\u622a\u56fe\u7684y\u5750\u6807 \r\nim = ImageGrab.grab(bbox) \r\nim.save('as.png')#\u4fdd\u5b58\u622a\u56fe\u6587\u4ef6\u7684\u8def\u5f84 \r\n<\/pre>\n7. ipython<\/strong><\/span><\/div>\n\u6700\u540e\u4ecb\u7ecd\u7684\u793a\u4e00\u4e2a\u5f3a\u5927\u7684python\u5de5\u5177\u2014\u2014IPython \u3002
\nIPython \u652f\u6301\u53d8\u91cf\u81ea\u52a8\u8865\u5168\uff0c\u81ea\u52a8\u7f29\u8fdb\uff0c\u652f\u6301 bash shell \u547d\u4ee4\uff0c\u5185\u7f6e\u4e86\u8bb8\u591a\u5b9e\u7528\u529f\u80fd\u548c\u51fd\u6570;
\n\u5b83\u662f\u4e00\u4e2a for Humans \u7684 Python \u4ea4\u4e92\u5f0f shell\uff0c\u7528\u4e86\u5b83\u4e4b\u540e\u4f60\u5c31\u4e0d\u60f3\u518d\u7528\u81ea\u5e26\u7684 Python shell \u4e86\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"
Python\u4f5c\u4e3a\u8d8a\u6765\u8d8a\u6d41\u884c\u7684\u4e00\u79cd\u7f16\u7a0b\u8bed\u8a00\uff0c\u4e0d\u4ec5\u4ec5\u662f\u56e0\u4e3a\u5b83\u8bed\u8a00\u7b80\u5355\uff0c\u6709\u8bb8\u591a\u73b0\u6210\u7684\u5305\u53ef\u4ee5\u76f4\u63a5\u8c03\u7528\u3002 python\u4e2d […]<\/p>\n","protected":false},"author":1898,"featured_media":163038,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[153],"class_list":["post-163024","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread","tag-python"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/163024","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/1898"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=163024"}],"version-history":[{"count":7,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/163024\/revisions"}],"predecessor-version":[{"id":164062,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/163024\/revisions\/164062"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/163038"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=163024"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=163024"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=163024"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}