Skip to content

Instantly share code, notes, and snippets.

View arischow's full-sized avatar
🐈
Focusing with my kittens Loki, Kasumi and Miumiu

Aris Chow arischow

🐈
Focusing with my kittens Loki, Kasumi and Miumiu
View GitHub Profile
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']
@arischow
arischow / get_all_files.py
Created October 21, 2016 02:24
获取某目录下的所有同类型文件
# 获取某目录下的所有同类型文件
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))
def opcount(fname):
with open(fname) as f:
for i, l in enumerate(f):
pass
return i + 1
# Check http://stackoverflow.com/questions/17285826/flask-redirecting-multiple-routes for more details.
# 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)
# -*- coding: utf-8 -*-
print('Hello, my Gist!')