import json
def jason_basic()
data ={"ID":1"课程":"优品课堂""单价":"98.00"}
json_str = json.dumps(data)//写在字符串里
json_data = json.loads(json_str)
def json_writer_filr():
data ={"ID":1"课程":"优品课堂""单价":"98.00"}withopen('data.json','w',encoding='utf8')as f:
json.dump(data,f)//不是写在字符串,而是直接写在文档,所以dump后不用s
读取json文件
import json
def json_read_filr():withopen('data.json','r',encoding ='utf8')as f:
data = json.load(f)print(data)
json和python语法区别
Python
Json
False
false
True
true
None
none
Excel
从Excel问价中读取信息
import xlrd
def xl_read()
book = xlrd.open_workbook('product.xls')for sheet in book.sheets():print(sheet.name)
def xl_read_dada():
book = xlrd.open_workbook('product.xls')
sheet = book.sheet_by_name("Product")print('工作簿':{}.format(sheet.name))print('数据行数':{}.format(sheet.rows))print('产品数据')for i inrange(sheet.rows):print(sheet.row_values(i))//获取索引指定的数据行