zoukankan      html  css  js  c++  java
  • 把数据成从数据库读出来, 进过修改在放到数据库里面去

    import psycopg2

    '''
    conn = psycopg2.connect(database="testdb", user="postgres", password="new.1234", host="127.0.0.1", port="5432")
    37 cursor=conn.cursor()
    38 cursor.execute("select id,name,password,singal from public.member where id>2")
    39 rows=cursor.fetchall()
    40 for row in rows:
    41 print 'id=',row[0], ',name=',row[1],',pwd=',row[2],',singal=',row[3],' '
    42 conn.close()
    '''
    def replace_row(row):
    row = str(row)
    row = row.replace("['", '')
    row = row.replace("']", '')
    row = row.replace("[]", '')
    row = row.replace("{", '')
    row = row.replace("}", '')
    row = row.replace("\r", '')
    row = row.replace("\n", '')
    row = row.replace('\','')
    row = row.replace('/', '')
    row = row.replace('"', '')
    return row

    conn = psycopg2.connect(database="postgres", user="postgres", password="123456", host="127.0.0.1",port="5432")
    cur = conn.cursor()

    cur.execute("select * from company_SQ")

    #cur.execute("DELETE FROM Employee WHERE name='Gopher'") # 删除
    rows = cur.fetchall()
    print(rows)

    print("rows",type(rows)) #list类型
    for row in rows:
    print("row",type(row)) #这样写 row 是tuple类型可以循环。

    li = []
    for r in row:
    repair = replace_row(r)
    li.append(repair) #
    # print(len(li))
    # print(li)
    # print(li[0])

    #item_my['register_money'] = re.findall('d{1,9}', item_my['register_money'])[0] 正则修改 注册资本的url

    cur.execute("INSERT INTO company_SQ_copy VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)", (li[0],li[1],li[2],li[3],li[4],li[5],li[6],li[7],li[8],li[9],li[10],li[11],li[12],li[13],li[14],li[15],li[16]))


    conn.commit()
    #关闭游标
    cur.close()
    conn.close()
  • 相关阅读:
    转载C#基础概念二十五问
    C# 文件路径、目录、I/O常见操作汇总
    最简单lru缓存及改进版本(java备忘)
    我的游戏观
    寂静岭 破碎的记忆
    居然又回来了,CSDN博客太不方便了
    Game Physics Engine Development 粗略翻译
    就这么定了
    绘画 程序 人生
    也谈Maxscript
  • 原文地址:https://www.cnblogs.com/yuanjia8888/p/9872080.html
Copyright © 2011-2022 走看看