Last active
May 8, 2020 15:54
-
-
Save Moekka/ffda124605bea14391684423cda45c6d to your computer and use it in GitHub Desktop.
[python] python常见使用 #python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
install | |
--- | |
pip install -r requirements.txt | |
--- | |
generate | |
--- | |
pip install pipreqs | |
pipreqs . --encoding=utf8 --force |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import shutil | |
shutil.rmtree(path) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
# 判断是否为目录 | |
os.path.isdir(path) | |
# 判断是否为文件 | |
os.path.isfile(path) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import chardet | |
coding = chardet.detect(string)['encoding'] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import platform | |
system = platform.system() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def fileCountIn(dir): | |
''' | |
读取目录及子目录下所有文件数 | |
''' | |
return sum([len(files) for root, dirs, files in os.walk(dir)]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//创建虚拟环境 | |
python3 -m venv venv | |
//使能 | |
venv\Scripts\activate | |
// 安装virtualenv | |
pip install virtualenv | |
// 创建虚拟环境 | |
virtualenv venv |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def read_from_file(): | |
for line in open('share.txt'): | |
# print("line[%s]" % line.strip()) | |
yield line.strip() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment