请问下在 Python 中如何将一个数组的值赋给另外一个数组

2017-04-25 15:17:46 +08:00
 wangyu8460958
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 中如何将一个数组的值赋给另外一个数组?
6804 次点击
所在节点    问与答
1 条回复
konia
2017-04-25 16:11:41 +08:00
for 前定义 ids = [None] * len(aaa)
不过这么写很不科学…
直接 copy 不就好了…

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/357251

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX