7-5.11

连接redis
r = redis.Redis(host='118.24.3.40',password='HK139bc&*',db='13',decode_responses=True)
r.set('lidandan','haha’)
 
发邮件:
import yagmaill
yagmall.SMTP(user  password=授权码  host)
yagmall(to  cc  subject contens attachments=附件,绝对路径) 
 
 
 
__main__:
在被导入文件中if __main__ == ’__main__’,执行文件,引入文件main中内容不会被执行
引入其他文件夹中的文件:文件夹添加到环境变量 
 
 
 
写日志:
import nnlog
log = nnlog.Logger('test.log',level='error',backCount=5,when='S')
log.debug('返回结果...')#一些调试信息,看变量值这些
log.info('info...') #一些提示信息
log.warning('waring')#出警告了
log.error('error...')#出错的时候打印的
 
操作mysql
#!/usr/bin/python3 import pymysql
# 打开数据库连接
db = pymysql.connect("localhost","testuser","test123","TESTDB" )
# 使用 cursor() 方法创建一个游标对象
cursor cursor = db.cursor()
# 使用 execute() 方法执行 SQL 查询
cursor.execute("SELECT VERSION()")
# 使用 fetchone() 方法获取单条数据.
data = cursor.fetchone() print ("Database version : %s " % data)
# 关闭数据库连接 db.close()

猜你喜欢

转载自www.cnblogs.com/dandan33/p/10879320.html