Below is my code and when I run it, I get the following error (see below py code)
Need help....!!! What am I doing wrong?
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 #!/usr/bin/python3
2
3 # Remove old lines based on date - if content < 60 days = delete
4
5 import sys
6 import time
7 from datetime import datetime
8
9 now = datetime.now()
10
11 with open('test.log','r+') as x:
12 for line in x:
13 L = line.split('|')
14 before = datetime.fromtimestamp(
15 time.mktime(time.strptime(L[0],'%b %d %H:%M:%S %Y')))
16 old = now - before
17
18 if old.days < 60:
19 sys.stdout.write(line)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Traceback (most recent call last):
File "./rmoldline.py", line 15, in
time.mktime(time.strptime(L[0],'%b %d %H:%M:%S %Y')))
File "/usr/lib/python3.5/_strptime.py", line 504, in _strptime_time
tt = _strptime(data_string, format)[0]
File "/usr/lib/python3.5/_strptime.py", line 346, in _strptime
data_string[found.end():])
ValueError: unconverted data remains: : radsecproxy revision 1.6.5 starting
It looks like you're new here. If you want to get involved, click one of these buttons!
Comments
First, there is a button to format code, no need to write lines by hand.
Second, your
L[0]
contains more than date string.