This file contains 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 random | |
# 生成5个0~9的不重复随机数 | |
print random.sample(range(10), 5) | |
# [7, 9, 6, 2, 3] | |
# 从a~d中取出不重复的三个字母 | |
print random.sample(['a', 'b', 'c', 'd'], 3) | |
# ['d', 'b', 'c'] |
This file contains 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 | |
import fnmatch | |
matches = [] | |
for root, dirs, files in os.walk('/Users/arischow/Desktop/data'): | |
for file in fnmatch.filter(files, '*.txt'): | |
matches.append(os.path.join(root, file)) |
This file contains 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 opcount(fname): | |
with open(fname) as f: | |
for i, l in enumerate(f): | |
pass | |
return i + 1 |
This file contains 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
# Check http://stackoverflow.com/questions/17285826/flask-redirecting-multiple-routes for more details. |
This file contains 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
# Py 文件所在目录 | |
import os | |
print(__file__) # 包括文件名 | |
print(os.path.dirname(os.path.abspath(__file__))) | |
# REDIS SET ADD | |
import redis | |
r = redis.Redis(host='localhost', port=6379, db=0) |
This file contains 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
# -*- coding: utf-8 -*- | |
print('Hello, my Gist!') |
NewerOlder