exit(0):无错误退出 exit(1):有错误退出
This file contains hidden or 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 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) |
This file contains hidden or 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
| 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): |
This file contains hidden or 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
| 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 |
This file contains hidden or 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
| python | |
| >>> import django | |
| >>> print(django.VERSION) |
This file contains hidden or 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
| 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() | |
This file contains hidden or 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 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"): |
This file contains hidden or 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
| 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 ) | |
| ] ) |
This file contains hidden or 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
| 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)}) |
This file contains hidden or 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
| 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 |