zoukankan      html  css  js  c++  java
  • Python# Python通

    import pymysql
    import uuid
    # db = pymysql.connect(host='192.168.0.100',user='root',passwd='123456',db='mysql')
    #
    # cur = db.cursor()
    # # cur.execute("SELECT Host,User FROM user")
    # # cur.execute("SELECT version()")
    # cur.execute("SELECT * from testdb.person")
    #
    # print(cur.fetchall())
    #
    # cur.close()
    # db.close()
    
    
    
    
    # 生成 num 个验证码,每个长度为length,可设置默认长度
    def create_num(num,length=16):
        result = []
        while num > 0:
            uuid_id = uuid.uuid4()
            print(uuid_id)
            # 删去字符串中的'-',取出前length 个字符
            temp = str(uuid_id).replace('-', '')[:length]
            if temp not in result:
                result.append(temp)
                num -= 1
        return result
    
    # 保存到MySQL数据库
    def save_to_mysql():
        conn = pymysql.connect(host='192.168.0.100',user='root',passwd='123456',db='test1db')
        cur = conn.cursor()
        # cur.execute("INSERT INTO `jihuoma` (`id`, `name`) VALUES ('2', 'b')")
        # cur.execute("select * from test1db.jihuoma")
        conn.commit()
        print(cur.fetchall())
        cur.close()
        conn.close()
    save_to_mysql()
        # try:
        #     with conn.cursor() as cursor:
        #         # Create a new record
        #         sql = "INSERT INTO `jihuoma` (`code`) VALUES (%s)"
        #         cursor.execute(sql, code)
        #
        #         # connection is not autocommit by default. So you must commit to save
        #         # your changes.
        #         conn.commit()
        #
        #     with conn.cursor() as cursor:
        #         # Read a single record
        #         sql = "SELECT `id`, `code` FROM `jihuoma` WHERE `code`=%s"
        #         cursor.execute(sql, code)
        #         result = cursor.fetchone()
        #         print(result)
        # finally:
        #     conn.close()
    #
    # for code in create_num(20):
    #     save_to_mysql(code)
    #
  • 相关阅读:
    计算器部分代码
    学写压缩壳心得系列之二 掌握PE结构 ,曲径通幽
    headerfiles
    VC实现文件拖拽
    学写压缩壳心得系列之三 模拟加载,步步为营
    ASPack 2.x (without poly) > Alexey Solodovnikov [Overlay]脱壳
    学写压缩壳心得系列之一 熟悉概念,未雨绸缪
    upx最新壳脱壳测试
    正则表达式大全
    win7 iis http 500 错误
  • 原文地址:https://www.cnblogs.com/lwsup/p/7296512.html
Copyright © 2011-2022 走看看