title: Python: saving a new file deleting all data outside a given range of time
body: <p>i've a file like the following:</p>
  <pre><code>01/31/2021 08:51:41.222 5777 40.26
  01/31/2021 08:51:41.441 5802 40.26
  01/31/2021 08:51:41.644 5786 40.26
  01/31/2021 08:51:41.847 5793 40.29
  01/31/2021 08:51:42.050 5776 40.29
  01/31/2021 08:51:42.269 5798 40.29
  01/31/2021 08:51:42.456 5791 40.26
  01/31/2021 08:51:42.660 5800 40.26
  01/31/2021 08:51:42.878 5781 40.26
  01/31/2021 08:51:43.081 5793 40.29
  01/31/2021 08:51:43.300 5795 40.29
  01/31/2021 08:51:43.519 5799 40.29
  </code></pre>
  <p>Named for example file.txt, i'm just interested in date and time and the third value; not interested with the last one. Like for example <strong>01/31/2021 08:51:42.878 5781</strong>. So i've a time and a value i'm interested with.
  My aim is to select a range of time and save all the things in this range into a new file because i've a really long list in this first file, like datas from the whole day but i'm interested in something like 50 minutes.
  Imagine from the given example i want only to save data at 8:51:42 and delete the other things. I want to have a new file with this lines in the end (to be honest the last value, the temperature, is not needed):</p>
  <pre><code>01/31/2021 08:51:42.269 5798 40.29
  01/31/2021 08:51:42.456 5791 40.26
  01/31/2021 08:51:42.660 5800 40.26
  01/31/2021 08:51:42.878 5781 40.26
  </code></pre>
  <p>That's what i'm trying to code:</p>
  <pre><code>start = (input('Insert starting time for your range:'))
  end = (input('Insert ending time for your range:'))
  
  with open(r&quot;C:\Users\Username\Desktop\file.txt&quot;, &quot;r&quot;) as fp:
      lines = fp.readlines()
      date = [line.split()[0] for line in lines]  
      hours = [line.split()[1] for line in lines]
      signal = [float(line.split()[2]) for line in lines]
      temperature = [float(line.split()[3]) for line in lines]
  
  full_time = [d + h for d,h in zip(date, hours, start, end)]
  datetime_object = [datetime.strptime(ft, '%d/%m/%Y%H:%M:%S.%f') for ft in full_time]
  bad_time = ['start','end']
  with open('file.txt') as oldfile, open('newfile.txt', 'w') as newfile:
      for line in oldfile:
          if not any(    ):
              newfile.write(line)
  </code></pre>
  <p>I'm experiencing problem already when manually writing start and end date and time because there are problems while converting into the datetime_object.
  But i'm also wondering how can i remove all the lines i'm not interested with and finally save my file. Infact there are missing stuff on this topic in the code, i was trying to find a solution but already got headache so I've decided to ask for help here instead of exploring pages with the search bar :p
  All the help or external documentations would be appreciated.
  I'm pretty a newbie with python, don't eat me please if possible :)</p>
  <p>\ edit: What i want to do is: the user define start time and end time, then save lines from the files between start and end, delete the 4th value and write all into a new file.</p>