#python文件读写对象
x,y,z = 1,2,3
name='woxiaoe'
d={'a':1,'b':2}
l = ['a','b','c']
file = open('object','w')
file.write(name + '\n')
file.write('%s,%s,%s\n' %(x,y,x));
file.write(str(d) + '$' + str(l) + '\n');
file.close();
#读入
file = open('object','r');
bytes = file.read();
print(bytes);
file.close();
file = open('object','r');
print(file.readline());
print(file.readline().split(','))
str = file.readline();
print(eval(str.split('$')[0]))
print(eval(str.split('$')[1]))
output
woxiaoe
1,2,1
{'a': 1, 'b': 2}$['a', 'b', 'c']
woxiaoe
['1', '2', '1\n']
{'a': 1, 'b': 2}
['a', 'b', 'c']