Skip to content

Instantly share code, notes, and snippets.

View Everfighting's full-sized avatar
😁
I may be slow to respond.

蔡大锅 Everfighting

😁
I may be slow to respond.
View GitHub Profile
@Everfighting
Everfighting / cuishou.sh
Created October 10, 2017 05:56
每天自动运行python脚本生成催收统计报告,发送给相关同事
#!/bin/bash
. ~/.bash_profile
. ~/virtualenv/bin/activate
dt=`date +'%Y-%m-%d'`
day=`date +'%Y%m%d'`
cd virtualenv/report
python main.py --table 催收DL $dt
@Everfighting
Everfighting / slots.py
Created September 7, 2017 08:38
python中 __slots__
class Person(object):
__slots__ = ('name', 'gender')
def __init__(self, name, gender):
self.name = name
self.gender = gender
class Student(Person):
@Everfighting
Everfighting / new_gist_file.py
Created September 7, 2017 03:11
找到最大或最小的N个元素
import heapq
dicts = [
{'name':'cbb','price':1221},
{'name':'bbc','price':212},
{'name':'cbc','price':12},
{'name':'bcb','price':112}
]
print(heapq.nlargest(2, dicts, key=lambda s:s['price']))
print(heapq.nsmallest(2, dicts, key=lambda s:s['price']))
@Everfighting
Everfighting / using_name.py
Created August 24, 2017 03:53
A module's __name__ if __name__ == '__main__'
#!/usr/bin/python
# Filename: using_name.py
if __name__ == '__main__':
print 'This program is being run by itself'
else:
print 'I am being imported from another module'
# ------------output-----------------
$ python using_name.py
@Everfighting
Everfighting / bitwise_operators_example.py
Last active August 24, 2017 03:53
bitwise_operators_example & | ^ ~ >> <<
#!/usr/bin/python3
#coding=utf-8
#save file : bitwise_operators_example.py
a = 60 # 60 = 0011 1100
b = 13 # 13 = 0000 1101
print ('a=',a,':',bin(a),'b=',b,':',bin(b))
c = 0
mkdir test 创建放置文件的比对文件夹
git init 生成git本地仓库
touch a1.py 创建a1文件
git add 加入跟踪
git commit -m "a1" 提交至版本
删除a1.py中的代码,贴入新的代码
git add .跟踪文件  
git commit -m "a2" 提交新版本
git log  查看commit id信息
git diff commit_id1 commit_id2 -- a.py 笔记两次提交的内容的变化
setting.py
DEBUG = True # 通过这种方式可以打开 DEBUG 模式
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'filters': {
'require_debug_true': {
'()': 'django.utils.log.RequireDebugTrue',
}, # 针对 DEBUG = True 的情况
},
@Everfighting
Everfighting / learn_python_in_1000_lines.py
Last active August 10, 2017 05:24
learn_python_in_1000_lines
# 作者:xianhu
# 链接:https: // zhuanlan.zhihu.com / p / 22909144
'''类型和运算----类型和运算----类型和运算----类型和运算----类型和运算----类型和运算----类型和运算----类型和运算----类型和运算----类型和运算----类型和运算----类型和运算----类型和运算'''
# -- 寻求帮助:
dir(obj) # 简单的列出对象obj所包含的方法名称,返回一个字符串列表
help(obj.func) # 查询obj.func的具体介绍和用法
# -- 测试类型的三种方法,推荐第三种
@Everfighting
Everfighting / get_file_name
Last active June 21, 2017 06:46
How can i get the file name from request.FILES?
request.FILES['filename'].name
If you don't know the key, you can iterate over the files:
for filename, file in request.FILES.iteritems():
name = request.FILES[filename].name
cur.execute(   ...     """INSERT INTO some_table (an_int, a_date, another_date, a_string)  ...        
VALUES (%(int)s, %(date)s, %(date)s, %(str)s);""",   ...     
{'int': 10, 'str': "O'Reilly", 'date': datetime.date(2005, 11, 18)})