#!/usr/bin/env python
# -*- coding: utf-8 -*-
# author: fanxuanhui
# @time: 22:49
# @file: 10-30_1.py
mylist=[3,4,2,1,5,9]
re_list=[]
mylist.sort()
print(mylist)
in_json=json.dumps(mylist)
with open('test.txt','w+') as fd:
for n in mylist:
fd.write(str(n))
if n < len(mylist):
fd.write(",")
with open("test.txt",'r+') as f1:
data=f1.read()
new_list=data.strip().split(",")
for i in new_list:
re_list.append(int(i))
re_list.reverse()
print(re_list)
print(len(re_list))
with open('test.txt','a') as f:
f.write(' ')
for x in re_list:
f.write(str(x))
f.write(",")
结果:
1,2,3,4,5,9
9,5,4,3,2,1,