temp = line.split( ' , ' ) all_data.append(temp) print ( ' ----------------------------- ' ) try : print (all_data) print (all_data[0]) print (all_data[-1 ][0]) except : all_data.clear() print ( ' ============================= ' ) file.seek(0) for line in file.readlines(): temp = line.replace( ' \n ' , "" ).split( ' , ' ) # 去掉换行 以逗号分隔 all_data.append(temp) try : print (all_data) print (all_data[0]) print (all_data[-1 ][0]) except : print ( ' ---------------------------- ' ) if int(all_data[0][0])==11 : print (all_data[0])

控制台打印

PS E:\python\python> & "E:/Program Files/Python38/python.exe" e:/python/python/python_all_by_me/文本处理/分割字符.py
-----------------------------
[['11', '12', '13\n'], ['21', '22', '23\n'], ['31', '32', '33\n'], ['41', '42', '43\n'], ['one', 'two', 'three']]
['11', '12', '13\n']
=============================
[['11', '12', '13'], ['21', '22', '23'], ['31', '32', '33'], ['41', '42', '43'], ['one', 'two', 'three']]
['11', '12', '13']
----------------------------
['11', '12', '13']
-------------====================分割线====================-------------

作者: 戳人痛处

本博客link: https://www.cnblogs.com/hardfood/p/14177278.html

硬币,懂?

https://space.bilibili.com/68973181