## 读写csv文件
csv_file = 'datas.csv'
csv = open(csv_file,'w')
for i in range(1,20):
csv.write(str(i) + ',')
if i % 10 == 0:
csv.write('\n')
csv.close()
result = []
with open(csv_file,'r') as f:
for line in f:
linelist = line.split(',')
linelist.pop()# delete: \n
for index, item in enumerate(linelist):
result.append(int(item))
print('\nResult is \n' , result)
Result is [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]
import os
json_dir = "../dir_json/2017-04/"
if not os.path.exists(json_dir):
print("json dir not found")
os.makedirs(json_dir)
print("Create dir " + json_dir)
import json json_file = open(json_dir + id + '.json', 'w', encoding='utf8') json_file.write(json.dumps(data_dict, ensure_ascii=False))
>>> data = [1,2,3] >>> for i, item in enumerate(data): print(i,item) 0 1 1 2 2 3
>>> line = 'one' >>> for i, item in enumerate(line,4): print(i,item) 4 o 5 n 6 e
>>> print(int('-100'),int('0'),int('3'))
-100 0 3
>>> int(7788)
7788
>>> int(7.98)
7
>>> int('2.33')
Traceback (most recent call last):
File "<pyshell#27>", line 1, in <module>
int('2.33')
ValueError: invalid literal for int() with base 10: '2.33'
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有