jingshen 发表于 2018-8-16 08:50:49

python玩转字符拼接

#!/usr/bin/env python  
# _*_ conding:utf-8 _*_
  
import sys
  
import os
  
import time
  
import datetime
  
import MySQLdb
  
today=datetime.date.today()
  
oneday=datetime.timedelta(days=1)
  
yesterday=today-oneday
  
yes_last=datetime.datetime.strftime(yesterday,"%Y%m%d")
  
#print yes_last
  
#print c_time
  
try:
  
    conn1=MySQLdb.connect(host='192.168.1.108',user='dlan',passwd='root123',port=3306,db='aa')
  
    cur1 = conn1.cursor()
  
    aa2 = "createtable aa_" + yes_last + "" + "as" + "" + "select * from test" + "" + "where" + "" + "date_format" + "(ti,'%Y%m%d')" + "=" + yes_last
  
    old_del = "delete from test" + "" + "where" + "" + "date_format" + "(ti,'%Y%m%d')" + "=" + yes_last
  
    cur1.execute(aa2)
  
    cur1.execute(old_del)
  
    conn1.commit()
  
    cur1.close()
  
    conn1.close()
  

  
except MySQLdb.Error,e:
  
    print "Could not connect to MySQL server",e


页: [1]
查看完整版本: python玩转字符拼接