Skip to content

Instantly share code, notes, and snippets.

@Moekka
Last active May 8, 2020 15:54
Show Gist options
  • Save Moekka/ffda124605bea14391684423cda45c6d to your computer and use it in GitHub Desktop.
Save Moekka/ffda124605bea14391684423cda45c6d to your computer and use it in GitHub Desktop.
[python] python常见使用 #python
install
---
pip install -r requirements.txt
---
generate
---
pip install pipreqs
pipreqs . --encoding=utf8 --force
import shutil
shutil.rmtree(path)
import os
# 判断是否为目录
os.path.isdir(path)
# 判断是否为文件
os.path.isfile(path)
import chardet
coding = chardet.detect(string)['encoding']
import platform
system = platform.system()
def fileCountIn(dir):
'''
读取目录及子目录下所有文件数
'''
return sum([len(files) for root, dirs, files in os.walk(dir)])
//创建虚拟环境
python3 -m venv venv
//使能
venv\Scripts\activate
// 安装virtualenv
pip install virtualenv
// 创建虚拟环境
virtualenv venv
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