-2
class Define_time:
def __init__(self):
    pass

d = Define_time()
d.real_time = time.strftime('%l:%M:%S')

def capture_time():
    d.real_time = time.strftime('%l:%M:%S')
    return d.real_time

while True:
    capture_time()
    if d.real_time == '3:37:00':
        time.sleep(1)
        s.login(smtpUser, smtpPass)
        s.sendmail(fromAdd, toAdd, header + '\n' + body)
        print('Email Sent')
        time.sleep(5)
    else:
        print(d.real_time)
7
  • check the length of the string
    – jsotola
    Commented Feb 14, 2020 at 20:55
  • also try if '3:37:00' == '3:37:00':
    – jsotola
    Commented Feb 14, 2020 at 20:56
  • So, the else-part prints "3:37:00" at that time each day, right?
    – Bob Brown
    Commented Feb 14, 2020 at 21:11
  • 1
    The script is incomplete and incorrectly formatted.
    – joan
    Commented Feb 14, 2020 at 21:17
  • The length of string seemed to be the problem. I changed it to ' 3:37:00': instead of '3:37:00': Thanks!
    – Mortiphus
    Commented Feb 14, 2020 at 23:18

2 Answers 2

2

%l if not part of standard formatting for python but assuming you are on Linux it's:

%l     The hour (12-hour clock) as a decimal number (range 1 to 12);
              single digits are preceded by a blank.  (See also %I.)
              (Calculated from tm_hour.)  (TZ)

Note: "single digits are preceded by a blank".

So your string is " 3:37:00".

I suggest using %H:%M:%S instead.

1

Looking for this code to solve the problem:

def capture_time():
    d.real_time = time.strftime('%H:%M:%S')
    return d.real_time

while True:
    capture_time()
    if d.real_time == '15:37:00':`

Not the answer you're looking for? Browse other questions tagged or ask your own question.