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 asyncio | |
import asyncpg | |
async def run(): | |
conn = await asyncpg.connect(user='user', password='password', | |
database='database', host='127.0.0.1') | |
values = await conn.fetch('''SELECT * FROM mytable''') | |
await conn.close() | |
loop = asyncio.get_event_loop() |
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
list1 = ["这", "是", "一个", "测试"] | |
for index, item in enumerate(list1, 1): | |
print index, item | |
#results | |
#1 这 | |
#2 是 | |
#3 一个 | |
#4 测试 | |
#修改了默认的起始位置 |
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 -*- | |
import pymysql | |
conn= pymysql.connect(host="localhost",user="root",passwd="admin",db="local_db",charset="utf8") | |
cursor = conn.cursor() | |
n = cursor.execute("select * from course") | |
for row in cursor.fetchall(): | |
for r in row: | |
print (r) | |
print(n) |
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 itertools | |
for i in itertools.chain([1, 2, 3], ['a', 'b', 'c']): | |
print(i,end=" ") | |
# 1 2 3 a 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
pip install -i http://pypi.douban.com/simple/ packagename | |
pip install -i http://pypi.tuna.tsinghua.edu.cn/simple packagename |
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
public class Operation | |
{ | |
private double _numberA = 0; | |
private double _numberB = 0; | |
public double NumberA | |
{ | |
get { return _numberA; } | |
set { _numberA = value; } | |
} |
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
class Operation: | |
def GetResult(self): | |
pass | |
class OperationAdd(Operation): | |
def GetResult(self): | |
return self.op1+self.op2 | |
class OperationSub(Operation): |
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 smtplib | |
from email.mime.text import MIMEText | |
from email.mime.multipart import MIMEMultipart | |
from email.mime.image import MIMEImage | |
from email.mime.application import MIMEApplication | |
#设置登录及服务器信息 | |
mail_host = 'smtp.163.com' | |
mail_user = '' #账号 | |
mail_pass = '' #密码(smtp服务器的密码) |
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
#!/usr/bin/env python3 | |
""" | |
email负责构造邮件 | |
smtplib负责发送邮件 | |
""" | |
from email.header import Header | |
from email.mime.text import MIMEText | |
from email.mime.multipart import MIMEMultipart | |
from email.utils import formatdate | |
import smtplib |
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 psycopg2 | |
import json | |
def load_db_config(): | |
with open('../conf/db0.conf', "r") as f: | |
config_json = json.loads(f.read()) | |
return config_json | |
config_json = load_db_config() |
OlderNewer