如下所示:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
# -*- 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() |
以上这篇python读取txt文件,去掉空格计算每行长度的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持服务器之家。
原文链接:https://blog.csdn.net/weixin_39012047/article/details/81457124