在使用MySQL时,常常会用到Load Data Infile来导入数据,在遇到Date类型的列时,有时会遇到格式转换的问题: 首先创建一张简单的people表,包含名字,生日,年龄三个字段: mysql> create table people( -> name varchar(10) NOT NULL, -> birthday date NOT NULL, -> age int NOT NULL); Query OK, 0 rows affected (
下面是一个简单的csv文件 Title,Release Date,Director And Now For Something Completely Different,1971,Ian MacNaughton Monty Python And The Holy Grail,1975,Terry Gilliam and Terry Jones Monty Python's Life Of Brian,1979,Terry Jones Monty Python Live At The Hollyw
在用csv.writer写入文件的时候发现中间有多余的空行. 最早打开方式只是‘w’,会出现多余的空行,网上建议使用binary形式‘wb’打开可以解决问题: with open('egg2.csv', 'wb') as cf: 不过只能在python2下运行,python3报错: TypeError: a bytes-like object is required, not 'str' 有人建议用encode(‘utf-8’)编码转变格式,但是觉得还是比较繁琐,因为list也不支持直接的编码.
需求:将utf-8格式的文件转换成gbk格式的文件 实现代码如下: def ReadFile(filePath,encoding="utf-8"): with codecs.open(filePath,"r",encoding) as f: return f.read() def WriteFile(filePath,u,encoding="gbk"): with codecs.open(filePath,"w",encodi