import time
import random
for j in range(1,50): #会执行49次
number = []
time.sleep(10) #每隔10秒执行一次
for i in range(0, 5):
num = random.randint(0,100000) #随机数字范围0-100000
number.append(num)
print(number)
====================================================
python连接mysql数据库
建立数据库 XUEXI_20220719
建立表 age1,一个列 age,目前插入一个数据33
print(“python数据库查询====”)
try:
conn = pymysql.connect(host=‘localhost’, user=‘root’, passwd=‘song1984_’, db=‘XUEXI_20220719’, port=3306, charset=‘utf8’)
cur = conn.cursor()
cur.execute(‘select * from age1’)
# 获取多条数据
blogs = cur.fetchall()
print(type(blogs))
for blog in blogs:
print(blog)
cur.close()
conn.close()
except Exception:
print(“发生异常”)
================================================================
插入数据
import pymysql
conn = pymysql.Connect(host=‘127.0.0.1’, port=3306,user=‘root’,password=‘song1984_’, db=‘XUEXI_20220719’,
charset=‘utf8’)
cursor = conn.cursor()
try:
sql = ‘insert into age1 (age) values (%s)’
values = ( 322)
cursor.execute(sql, values)
conn.commit()
except Exception as e:
print(‘一场异常’, e)
conn.rollback()
================================================
删除
import pymysql
conn = pymysql.Connect(host=‘127.0.0.1’, port=3306,user=‘root’,password=‘song1984_’, db=‘XUEXI_20220719’,
charset=‘utf8’)
cursor = conn.cursor()
try:
sql = ‘delete from age1 where age= (%s)’
values = ( 322)
cursor.execute(sql, values)
conn.commit()
except Exception as e:
print(‘一场异常’, e)
conn.rollback()