Original content: 11111, 222222, 3333333333333, 44445, 555, 66666666666, 777777 I
want to turn a row into multiple columns.
This article is divided into two types: the
first type: split and then change to vertical rows.
The second type: directly turn text or numbers into Vertical line
Article Directory
1. Change to a vertical line after splitting
1.1 Method 1. Split first, then print
1.1.1 First sorted into a dictionary
f = open('D://hello.txt', 'rb') # 以只读方式打开一个文件,获取文件句柄,如果是读的话,r可以不写,默认就是只读,
line = f.readlines()
for i in line:
data = i.decode()#截取空格
strlist = data.split('、')
print(strlist)#取第一列
f.close()
1.1.2 Traverse the dictionary again.
a=['11111', '222222', '3333333333333', '44445', '555', '66666666666', '777777']
for x in a:
print(x)
1.2 Split + merge
You can combine 2 logics in one
f = open('D://hello.txt', 'rb') # 以只读方式打开一个文件,获取文件句柄,如果是读的话,r可以不写,默认就是只读,
line = f.readlines()
for i in line:
data = i.decode()#截取空格
strlist = data.split('、')#字符之间用、隔开
for X in strlist:
print(X)
f.close() # 关闭文件
Second, change the horizontal to vertical
s='开发测试说明书'
for i in s:
print(i)
Three, summarize the application
The first type: mainly used for testing and writing document content.
The second type: mainly used for writing document cover.