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()
  • 相关阅读:
    Android系统在新进程中启动自定义服务过程(startService)的原理分析
    Thread和Service应用场合的区别
    Android数据格式解析对象JSON用法
    数据交换格式XML和JSON对比
    Android Handler的使用
    Android之Handler用法总结
    Handler的另外一种用法(HandlerThread)
    solr原理
    mysql主从:主键冲突问题
    修改mysql数据库存储目录
  • 原文地址:https://www.cnblogs.com/yuanjia8888/p/9872080.html
Copyright © 2011-2022 走看看