python第五章自己的笔记总结(3)

第一次

import pickle as p #起别名

from pickle import dumps,loads 另一种引用方法

s="hello python"
b=p.dumps(s) #把字符串转换成二进制
print(b)  #b'\x80\x03X\x0c\x00\x00\x00hello pythonq\x00.'

s01=p.loads(b) #将二进制转换成python数据类型
print(s01)  #hello python

“”"
“”"

数据类型的转换

dumps(数据类型,文件对象) 将python转换成二进制写入文件
loads(文件对象) 将文件中的数据读取成二进制转换成python数据类型

“”"

“”"

第二次

import pickle as p

1.创建文件 只能执行一次

#open("test.txt","x")
s="hello python"

2.创建文件对象 二进制写入文件

“”"
“”"

file01=open("test.txt","bw")
s="hello python"
p.dumo(s,file01)

“”"

“”"

第三次

1.创建文件对象 二进制读取文件

file02=open("test.txt","br")
p.load(file02)
print(a) #hello

创建数据库

create database tempDb;

使用数据库

use tempDb;

创建教师表

create table   if   not   exists    teacher(
    teacherID int primary key auto_increment,
    teacherName  varchar(10),
    money int not null,
    entryTime date,
    teacherSex char(10) default "boy"    
);

班级表

create table if not exists classInfo(
    classID int primary key auto_increment,
    className  varchar(20),
    teacherID int,#外键和主键的数据类型必须一样
    foreign key(teacherID) references teacher(teacherID)
);

创建学生信息表

create table if not exists student(
    studentID int primary key auto_increment,
    studenName   varchar(10),
    studentSex char(10) default "boy",
    studentbirthday varchar(10),
    studentcall  int(20),
    studentsfz varchar(20)  unique
);

创建科目表

create table if not exists subject(
    subjectID  int primary key auto_increment,
    subjectName varchar(10)
);

创建成绩单

create table if not exists grades(
    gradesID int primary key auto_increment,
    subjectID int,
    studentID int,
    foreign key(subjectID) references grades(gradesID),
    foreign key(studentID) references grades(gradesID)
);

插入数据

insert   into   student(studenName,studentSex,studentbirthday,studentcall,studentsfz)    values
('徐新宇','boy','5-23','134605635','41023200200014'),
('韩文','boy','6-24','162605635','4105241420014'),
('就这','boy','8-23','1345635','41023200254014'),
('王晶','boy','9-23','13498635','41020645220014'),
('董卿','boy','5-25','13452155','41023233220014'),
('凌动','boy','1-23','134565635','410232006761'),
('万古','boy','3-23','134925635','41023203457220014'),
('天帝','boy','2-23','13415635','413200245612324'),
('徐京','boy','9-23','13365635','42002546786014'),
('李刚','boy','7-23','134415635','4102256220014');
insert into subject(subjectName) values
('张三'),
('李四'),
('王五'),
('赵六'),
('徐七'),
('吴八'),
('就这'),
('小智'),
('theshy'),
('三大');
insert into grades(studentid,subjectid) values
(01,1),
(02,2),
(03,3),
(04,4),
(05,5),
(06,6),
(07,7),
(08,8),
(09,9),
(10,10);
"""
import pymysql
db=pymysql.connect(
    host="localhost",
    user="root",
    password="123456",
    port=3306,
    db="tempdb",
    charset="utf8"
)

创建游标对象—>负责执行sql语句

cur=db.cursor()
sql="show tables;"
a=cur.execute(sql)
print(a)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值