我想从文件中加载文本并在每行上排列 4 个单词
i want to load text from a file and arrange the text 4 words on each line
我想从文件中加载文本并将文本每行排列 4 个单词
with open(text_file, 'r') as f:
size_to_read = 100
lines = f.read(size_to_read)
while len(lines) > 0:
print(lines, end="")
lines = f.read(size_to_read)
您可以修改它以适合您的代码。
with open(text_file, 'r') as f:
size_to_read = 100
lines = f.read(size_to_read)
for key, val in enumerate(lines.split(), start=1) :
if key % 4== 0:
print(val, end='\n')
else:
print(val, end= ' ')
我想从文件中加载文本并将文本每行排列 4 个单词
with open(text_file, 'r') as f:
size_to_read = 100
lines = f.read(size_to_read)
while len(lines) > 0:
print(lines, end="")
lines = f.read(size_to_read)
您可以修改它以适合您的代码。
with open(text_file, 'r') as f:
size_to_read = 100
lines = f.read(size_to_read)
for key, val in enumerate(lines.split(), start=1) :
if key % 4== 0:
print(val, end='\n')
else:
print(val, end= ' ')