python学习记录
一、python的文件读写
1. 基本流程
filename=‘路径名称’
file=open(filename,‘控制命令’)
file.write()
file.read()
file.close()
2. 控制命令
指针在开始的话,会在下一次打开同一个文件时,覆盖之前已经写入的数据。
若文件不存在,控制命令为‘r’、‘r+’会报错;而那些会自动创建文件的控制命令不会报错
3、扩充 键盘读写
二、python的逻辑运算符
python运算符 学习连接
注意 *[HTML]:和Java不太一样!
按位运算:
逻辑控制:
赋值运算:
(1)幂赋值运算:c=3
c=**3 后 c的值变为 27(幂运算)
(2)取整除赋值运算符:c=8
c =// 3 后 c的值变为2(取整除 - 返回商的整数部分,向下取整)
c=-9
c=//2 后 c的值变为-5
(3)取模运算:返回除法的余数
三、万级以上的数据录入
转载地址
1、executemany()
execute(sql) : 接受一条语句从而执行
executemany(templet,args):能同时执行多条语句,执行同样多的语句可比execute()快很多,强烈建议执行多条语句时使用executemany
sql模板字符串:
例如 ‘insert into table(id,name,age) values(%s,%s,%s)’
args: 模板字符串中的参数,是一个list,在list中的每一个元素必须是元组!!!
例如: [(1,‘mike’),(2,‘jordan’),(3,‘james’),(4,‘rose’)]
2、load data infile
load data infile ‘/var/lib/mysql-files/data.txt’ into table ‘表名’(字段名)
(我不常用)可看转载链接
四、记录程序运行时间
参考文献链接
1. import time
time包 包含所需要用到的时间格式、数字
2. time.time()
创建时间,是从初始时刻到目前的秒数
3. time.gmtime()
获取初始时间,Unix内核的操作系统一般是1970,01,01,00:00:00(UTC)
4.time.localtime()
获得struct_time格式的当前时间,或将时间转换成struct_time格式
学习链接
5.strftime(format,p_tuple=None)
将struct_time格式的时间转换成自定义格式的时间
6. 时间的格式之间的转换
五、多进程
六、判断数字的几种方法对比
学习链接
num = “1” #unicode
num.isdigit() # True
num.isdecimal() # True
num.isnumeric() # True
num = “1” # 全角
num.isdigit() # True
num.isdecimal() # True
num.isnumeric() # True
num = b"1" # byte
num.isdigit() # True
num.isdecimal() # AttributeError ‘bytes’ object has no attribute ‘isdecimal’
num.isnumeric() # AttributeError ‘bytes’ object has no attribute ‘isnumeric’
num = “IV” # 罗马数字
num.isdigit() # True
num.isdecimal() # False
num.isnumeric() # True
num = “四” # 汉字
num.isdigit() # False
num.isdecimal() # False
num.isnumeric() # True
===================
isdigit()
True: Unicode数字,byte数字(单字节),全角数字(双字节),罗马数字
False: 汉字数字
Error: 无
isdecimal()
True: Unicode数字,,全角数字(双字节)
False: 罗马数字,汉字数字
Error: byte数字(单字节)
isnumeric()
True: Unicode数字,全角数字(双字节),罗马数字,汉字数字
False: 无
Error: byte数字(单字节)