• 把数据成从数据库读出来, 进过修改在放到数据库里面去


    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()
  • 相关阅读:
    10gen发布MongoDB增量备份服务
    JSON.NET 5中的架构变更
    Snowbox 2.0 发布,POP3 邮件服务器
    资源监控工具 glances
    Druid 0.2.18 发布,阿里巴巴数据库连接池
    Groovy 更新到 2.0.8 and 2.1.3
    Apache Libcloud 0.12.4 发布,统一云计算接口
    Go1.1性能测试报告(和C差距在10%以内)
    Apache Camel 2.11.0 发布,规则引擎
    2010年01月01日0时0分 总结我的2009
  • 原文地址:https://www.cnblogs.com/yuanjia8888/p/9872080.html
Copyright © 2020-2023  润新知