# 将文本文件data.txt中所有整数按升序排序后写入文本文件data_asc.txt
with open('data.txt', 'r', encoding='utf-8') as file:
    lineList = file.readlines()
# 将字符串元素构成列表lineList转为由整数构成的列表dataList
dataList = []
for line in lineList:
    # 删除末尾的\n字符后转成整数后再添加到列表
    dataList.append(int(line.strip('\n')))
# 对dataList列表按升序排序
dataList.sort()
# 将整数列表dataList转为整数\n格式的字符串列表lineList
lineList = []
for data in dataList:
    lineList.append(str(data) + '\n')
# 将字符串列表lineList写入到文件
with open('data_asc.txt', 'w', encoding='utf-8') as file:
    file.writelines(lineList)