list1=['selenium','appium','android','ios','uiautomator']
#json.dump()用于将dict类型的数据转成str,并写入到txt/json文件中。
with open(r'C:\Users\wangli\PycharmProjects\Test\Test\1.txt','w') as f:
json.dump(list1,f)
#json.load()用于从txt/json文件中读取数据
with open(r'C:\Users\wangli\PycharmProjects\Test\Test\1.txt','r') as f:
print(json.load(f))
['selenium', 'appium', 'android', 'ios', 'uiautomator']
#pickle(dump,load)文件内容进行序列化和反序列化
list2=['selenium','appium','android','ios']
# dump 将数据通过特殊的形式转换为只有python语言认识的字符串,并写入文件
with open(r'C:\Users\wangli\PycharmProjects\Test\Test\2.txt','wb') as f:
pickle.dump(list2,f)
# load 从数据文件中读取数据,并转换为python的数据结构
with open(r'C:\Users\wangli\PycharmProjects\Test\Test\2.txt','rb') as f:
print(pickle.load(f))
['selenium', 'appium', 'android', 'ios']