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()
  • 相关阅读:
    dedecms调用新增加的内容模型字段
    dedecms另一种单页制作方法
    dedecms文章列表加上序号效果
    解析DeDecms系统的SEO内部优化技巧
    织梦dedecms如何对列表添加判断语句
    织梦DEDE CMS文章列表arclist标签大全
    织梦dedecms 幻灯片 自定义设置
    当前标签dede[field:**] 标签调用说明
    织梦dedecms中的{dede:php}{/dede:php}的详细用法
    uva1628 Pizza Delivery
  • 原文地址:https://www.cnblogs.com/yuanjia8888/p/9872080.html
Copyright © 2011-2022 走看看