[英]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.