这是一个创建于 2771 天前的主题,其中的信息可能已经有所发展或是发生改变。
import MySQLdb
import numpy as np
conn = MySQLdb.connect(host='192.168.18.70',port = 3306,user='root',passwd='123456',db='st')
cur = conn.cursor()
conn.autocommit(1)
query_sql = "select id from st.baidu where created_at < date_sub(now(), interval 1 year);"
insert_sql = "insert ignore into tmp.baidu_bak (select * from st.baidu where id = %s);"
delete_sql = "delete from st.baidu where id = %s;"
cur.execute(query_sql)
aaa = cur.fetchall()
aaa = np.array(aaa)
for i in range(0,len(aaa)):
ids[i] = aaa[i]
if i%10000==0 :
cur.executemany(insert_sql,ids)
ids = null
我在 eclipse 写这段程序的时候,在第 16 行: ids[i] = aaa[i] 报错:
Undefined variable: ids
请问下在 Python 中如何将一个数组的值赋给另外一个数组?
|
|
1
konia 2017-04-25 16:11:41 +08:00 via iPhone
for 前定义 ids = [None] * len(aaa) 不过这么写很不科学… 直接 copy 不就好了…
|