V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
wangyu8460958
V2EX  ›  问与答

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

  •  
  •   wangyu8460958 · 2017-04-25 15:17:46 +08:00 · 6798 次点击
    这是一个创建于 2565 天前的主题,其中的信息可能已经有所发展或是发生改变。
    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
        1
    konia  
       2017-04-25 16:11:41 +08:00 via iPhone
    for 前定义 ids = [None] * len(aaa)
    不过这么写很不科学…
    直接 copy 不就好了…
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1023 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 18:17 · PVG 02:17 · LAX 11:17 · JFK 14:17
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.