10/21/2015 10:16:42 AM Following hmac:c35330404902c0b1bb5c6d0718407ea12b25a464433bd1e69152ccc0e0b89c9f with is already in database so dropping
11/21/2015 10:16:42 AM The data for the duplicate Hmac is : HF 13300100012015-06-15 19:30:21+0000+ 12.61 0.010 1686.00
07/21/2015 10:16:42 AM Following hmac:84d9cdb2145b7c3e0fa2d099070b7bd291c652f30ca25c69240e33ebbd2b8677 with is already in database so dropping
07/21/2016 10:16:42 AM The data for the duplicate Hmac is : HF 13300100012015-06-15 20:16:18+0000+ 12.60 0.045 1686.00
07/20/2016 10:16:42 AM Following hmac:a24d19d340651e694bff854ae7469dd779b60037228bf047d8f372dee4a731e0 with is already in database so dropping
07/20/2016 10:16:42 AM The data for the duplicate Hmac is : HF 13300100012015-06-15 20:31:25+0000+ 12.62 0.045 1685.00
07/20/2016 10:16:42 AM Following hmac:4e239a4b69108833e9cbc987db2014f9137679860df0ca8efdf7d09c4897d369 with is already in database so dropping
07/19/2016 10:16:42 AM The data for the duplicate Hmac is : HF 13300100012015-06-15 20:46:27+0000+ 12.61 0.040 1685.00
내 목표는 라인과 HMAC 포함 라인 특정 문자의 복귀 카운트 이상 루프 내 로그 파일의 일부 몇 줄 수 있습니다. 이미 총 수를 계산했지만 지난 1 년 동안의 줄 수를 반환하고 싶습니다. 각 줄의 날짜 부분을 추출하려고하는 오류를 나에게
ValueError를주고있다 : 변환되지 않은 데이터가 남아 : 내가 시도했지만 해결책을 찾을 수 없습니다
. 여기
def fileCount(fileName):
with open(fileName) as FileObj:
Count = 0
todayDate = date.today()
OneYear = str(todayDate - timedelta(days=365))
OneMonth = str(todayDate - timedelta(days=30))
ThreeMonths = str(todayDate - timedelta(days=90))
while True:
line = FileObj.readline()
Lines = "-".join(line[:11].split("/"))
convertDate = datetime.strptime(Lines, '%m-%d-%Y')
print convertDate
if not line:
break
if "Following hmac" in line:
Count += 1
print "The total count is ", Count
# Call The function
def main():
filePath = 'file.txt'
fileCount(filePath)
if __name__ == "__main__":
main()
내가하는 것입니다 날짜 산술 연산을 위해 사용하는 날짜를 추출 할 날짜 수입 timedelta에서 날짜 가져 오기 날짜 에서 날짜 가져 오기 시간 에서 날짜 가져 오기 날짜 에서 내 코드 수입 OS입니다 지난 3, 6, 12 개월 동안 카운트를 돌려 주도록 허락 해주세요.
합니다. 빠른 응답에 감사드립니다. 제안 된 솔루션 중 하나를 시도하면 또 다른 오류 ValueError가 발생합니다 : 시간 데이터 ''이 '% m- % d- % Y'형식과 일치하지 않습니다. 파이썬 2.7을 사용하고 있습니다. – user1895915
파일에 빈 줄이 있습니다. 날짜 문자열을 포함하는 행만 구문 분석해야합니다. 해당 코드 행을'try/except ValueError'에 랩핑하십시오. 답변에서 업데이트를 참조하십시오. –