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
>>> import pickle
>>> f = open('somedata', 'wb')
>>> pickle.dump([1, 2, 3, 4], f)
>>> pickle.dump('hello', f)
>>> pickle.dump({'Apple', 'Pear', 'Banana'}, f)
>>> f.close()
>>> f = open('somedata', 'rb')
>>> pickle.load(f)
[1, 2, 3, 4]
>>> pickle.load(f)
@Everfighting
Everfighting / datetime_demo.py
Created May 19, 2017 09:02
datetime和xlwt结合的相关操作
from datetime import datetime
import xlwt
workbook = xlwt.Workbook()
worksheet = workbook.add_sheet('sheet1',cell_overwrite_ok=True)
jy_ts = datetime.strptime(jy_dt, '%Y-%m-%d')
FIXED_COLS = ('统计日期', '星期', '月份')
for i, val in enumerate(FIXED_COLS):
@Everfighting
Everfighting / strongtype
Created May 24, 2017 05:12
python是强类型的语言,不是脚本语言就一定是弱类型语言。看Python与Javascript的对比。
Python强类型:不同类型不能够进行运算。
>>> 3+6
9
>>> "3"+6
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: Can't convert 'int' object to str implicitly
@Everfighting
Everfighting / django_demo
Created May 24, 2017 06:08
Django的相关知识点
python
>>> import django
>>> print(django.VERSION)
@Everfighting
Everfighting / genfaker.py
Created June 1, 2017 07:46
faker快速制造django假数据
from faker import Factory
fake = Factory.create()
for i in range(100):
c = CusQuestions(
que_no = fake.text(max_nb_chars=90),
loan_no = fake.text(max_nb_chars=90),
)
c.save()

exit(0):无错误退出 exit(1):有错误退出

import smtplib
from os.path import basename
from email.mime.application import MIMEApplication
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.utils import COMMASPACE, formatdate
def send_mail(send_from, send_to, subject, text, files=None,
server="127.0.0.1"):
c.executemany(
"""INSERT INTO breakfast (name, spam, eggs, sausage, price)
VALUES (%s, %s, %s, %s, %s)""",
[
("Spam and Sausage Lover's Plate", 5, 1, 8, 7.95 ),
("Not So Much Spam Plate", 3, 2, 0, 3.95 ),
("Don't Wany ANY SPAM! Plate", 0, 4, 3, 5.95 )
] )
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)})
@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