python tip
- 迭代一个数组:1234array = [1, 2, 3, 4, 5] # or whateverfor i in range(len(array)):# Do something with 'i'.
这是相当笨拙的,更干净简洁的做法是:1234array = [1, 2, 3, 4, 5] # or whateverfor i, e in enumerate(array): # Do something with index 'i' and its corresponding element 'e'.
序列数组
12zeroes = [0] * 100#会得到一个包含100个0的列表读取文件,以及写入文件内容的时候
12345678try:#追加的话,用a,重写里面内容,用w或者wbf = open('E:/study/python/test.text', 'a');print(f.write('This is add line!'))except Exception as e:raise efinally:f.close();调用os模块
12#在导入os模块之后。获取绝对路径时abspath('.'),括号里面的.要写os.path.abspath('.')发送邮件
123456789101112131415161718192021222324from email.mime.text import MIMETextfrom email.header import Headermsg = MIMEText('Hello, send myPython..', 'plain', 'utf-8');# 下面三个要写,不写的话会报错msg['From'] = 'zhoufa163537@163.com <zhoufa163537@163.com>'msg['Subject'] = Header(u'测试py', 'utf8').encode()msg['To'] = u'**<602512691@qq.com>'print(msg.as_string());# from_add = input("From:");from_add = 'zhoufa163537@163.com';psd = '*****';# 输入收件人地址:to_addr = '602512691@qq.com';# 输入SMTP服务器地址:smtp_server = 'smtp.163.com';import smtplibserver = smtplib.SMTP(smtp_server, 25);server.set_debuglevel(1);server.login(from_add, psd);server.sendmail(from_add, [to_addr], msg.as_string());server.quit();