当前位置:主页 > 软件编程 > Python代码 >

python读取txt文件,去掉空格计算每行长度的方法

时间:2021-08-02 07:30:00 | 栏目:Python代码 | 点击:

如下所示:

# -*- coding: utf-8 -*-

file2 = open("source.txt", 'r')

file1 = open("target.txt", "r")

for value1 in file1.readlines():
 word1 = str(value1).split()
 l1 = len(word1)
 print l1
for value2 in file2.readlines():
 word2 = str(value2).split()
 l2 = len(word2)
 print l2
file1.close()
file2.close()

您可能感兴趣的文章:

相关文章