Why is my condition in python not being met
<p>I have a list of filenames sorted by creation date. These files contain a datetime in the filename for their creation date time. I am attempting to create a sub list for all files after a certain time. </p>

<p>Full list of files -</p>

<pre><code>Allfilenames = ['CCN-200 data 130321055347.csv',
'CCN-200 data 130321060000.csv',
'CCN-200 data 130321063235.csv',
'CCN-200 data 130321070000.csv',
'CCN-200 data 130321080000.csv',
'CCN-200 data 130321090000.csv',
'CCN-200 data 130321100000.csv',
'CCN-200 data 130321110000.csv',
'CCN-200 data 130321120000.csv',
'CCN-200 data 130321130000.csv',
'CCN-200 data 130321140000.csv',
'CCN-200 data 130321150000.csv']
</code></pre>

<p><code>positions [19:24]</code> give the time in format hhmmss. I am using</p>

<pre><code>filenames = [s for s in Allfilenames if os.path.basename(s)[19:24] &gt;= TOffRound]

TOffRound = "080000"
</code></pre>

<p>The result should be a list of all filenames created  on or after or 08:00:00, however the resulting list is missing the "080000" file.</p>

<pre><code>filenames = ['CCN-200 data 130321090000.csv',
'CCN-200 data 130321100000.csv',
'CCN-200 data 130321110000.csv',
'CCN-200 data 130321120000.csv',
'CCN-200 data 130321130000.csv',
'CCN-200 data 130321140000.csv',
'CCN-200 data 130321150000.csv']
</code></pre>

<p>Why is the conditional not returning true on the = part of the condition and returning 'CCN-200 data 130321080000.csv' in my list? Please note I have only shown the basename here for clarity. </p>

<p>Instead of checking the time part as a string, I would suggest a stronger method to test the time part of your filename. This includes extracting the date part of the filename, retrieving the time value and comparing it on your specified time as a time object.</p>

<pre><code>import re
import datetime

TOffRound = datetime.time(8, 0)
filenames = []

for s in Allfilenames:
  datestr = re.search("[\d]{12}", s).group(0)
  dateobj = datetime.datetime.strptime(datestr,"%y%m%d%H%M%S")
  timeobj = dateobj.time()
  if timeobj &gt;= TOffRound:
    filenames.append(s)
</code></pre>

python