python的json模块
发布网友
发布时间:2022-04-24 00:35
我来回答
共1个回答
热心网友
时间:2022-05-10 05:03
json.load不是什么文件都能打开的。。。
Python 3.6.4 (v3.6.4:d48eceb, Dec 19 2017, 06:04:45) [MSC v.1900 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import json
>>> d = ['a', 'b', 'c']
>>> with open('a.log', 'w') as f:
... json.mp(d, f)
...
>>> with open('a.log') as f:
... print(f.read())
...
["a", "b", "c"]
>>> with open('a.log') as f:
... a = json.load(f)
... print(a)
...
['a', 'b', 'c']
>>> fname = 'logon_inf.log'
>>> s = [['w', 'w', 'w'], ['e', 'e', 'e'], ['w', 'w', 'w']]
>>> with open(fname, 'w') as f:
... json.mp(s, f)
...
>>> with open(fname) as f:
... print(f.read())
...
[["w", "w", "w"], ["e", "e", "e"], ["w", "w", "w"]]
>>> with open(fname) as f:
... a = json.load(f)
... print(a)
...
[['w', 'w', 'w'], ['e', 'e', 'e'], ['w', 'w', 'w']]