[英]Open a file and count number of occurrences of '|||'
我通过 sftp 拉入文件并且难以计算出现次数
try:
with open(os.path.join(args.local, file)) as rcount:
count= rcount.read().strip().split('|||')
#count = list(rcount)[-1].rstrip().split('|||')[1]
logging.info('Number of count: %d' % int(count))
name = match('([A-Z0-9]+)', file)
count 语句都不起作用。
在文件中将多次出现 YYYYMMDD|NNNNNNNNXXXXXX|Accepted|||
我的逻辑是计算 [|||] 在文件中出现的次数。 我也可以读出“接受”这个词。
正如@timgeb 所评论的,您可以使用字符串的count()
方法,例如:
with open(os.path.join(args.local, file)) as rcount:
count = rcount.read().count("|||")
logging.info('Number of count: %d' % int(count))
希望这可以帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.