python windows下创建目录
import shutil
import os
path = ['C:\Users\loujb\Downloads\files\gg','C:\Users\loujb\Downloads\files\cc']
由于这里是当前路径,所以需要把这个代码文件和你要处理的文件放到同一个文件夹里
path = str(os.path.join('C:\Users\loujb\Desktop\安装说明','cf'))
path = path.replace("\","/")
os.makedirs(path)
python的join函数
music = ["1","Rolling Stones","Black Sabbath","Metallica"]
music[1] = '\001'.join(["Rolling Stones","Black Sabbath","Metallica"])
print music[1]
用python发邮件
#-*- coding: utf-8 -*-
import smtplib
from email import encoders
from email.header import Header
from email.mime.text import MIMEText
from email.utils import parseaddr, formataddr
from_addr = '18267729117@163.com'
password = 'xxxxx' #用第三方客户端发邮件需要授权码而不是登录密码
to_addr = '362440932@qq.com'
smtp_server = 'smtp.163.com'
message = MIMEText('nizaiqiho', 'plain', 'utf-8')
message['From'] = '18267729117@163.com' # 发送者
message['To'] = '362440932@qq.com' # 接收者
message['Subject'] = Header('fangjiatongzhi', 'utf-8')
server = smtplib.SMTP(smtp_server,25)
server.set_debuglevel(1)
server.login(from_addr, password)
server.sendmail(from_addr, [to_addr], message.as_string())
server.quit()
用python连接数据库
import pymysql
# 打开数据库连接
db = pymysql.connect(
host='xxxxxx',
port=3306,
user='loujb',
passwd='xxxxxx',
db='loujb_test',
charset="utf8"
)
# 使用 cursor() 方法创建一个游标对象 cursor
cursor = db.cursor()
# 使用 execute() 方法执行 SQL 查询
cursor.execute("SELECT VERSION()")
# 使用 fetchone() 方法获取单条数据.
data = cursor.fetchone()
print ("Database version : %s " % data)
# 关闭数据库连接
db.close()
网友评论