• Subtracting dates to get hours and minutes

    From Steve GS@21:1/5 to All on Mon Dec 12 01:01:43 2022
    How do I subtract two time/dates and calculate the hours and minutes
    between?
    Steve

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Mike Dewhirst@21:1/5 to All on Mon Dec 12 19:13:02 2022
    SSBoYXZlIHNlZW4gdmFzdCBjb252ZXJzYXRpb25zIG9uIHRoaXMgdG9waWMgYnV0IGlmIGV2ZXJ5 dGhpbmcgaXMgaW4gdGhlIHNhbWUgdGltZS16b25lIGFuZCBkYXlsaWdodCBzYXZpbmcgc3dpdGNo b3ZlcnMgYXJlIG5vdCBpbnZvbHZlZCBpdCBpcyByZWxhdGl2ZWx5IHN0cmFpZ2h0Zm9yd2FyZC5D aGVjayB0aGUgdGltZWRlbHRhIGRvY3MuIE9yIGNvbnZlcnQgZGF0ZXRpbWVzIHRvIG9yZGluYWxz IGFuZCBzdWJ0cmFjdCB0aGVuIGNvbnZlcnQgdGhlIHJlc3VsdCB0byB3aGF0ZXZlciB1bml0cyBw bGVhc2UgeW91Lk0tLShVbnNpZ25lZCBtYWlsIGZyb20gbXkgcGhvbmUpCi0tLS0tLS0tIE9yaWdp bmFsIG1lc3NhZ2UgLS0tLS0tLS1Gcm9tOiBTdGV2ZSBHUyA8R3JvbmljdXNAU0dBLk5pbmphPiBE YXRlOiAxMi8xMi8yMiAgMTc6MzQgIChHTVQrMTA6MDApIFRvOiBweXRob24tbGlzdEBweXRob24u b3JnIFN1YmplY3Q6IFN1YnRyYWN0aW5nIGRhdGVzIHRvIGdldCBob3VycyBhbmQgbWludXRlcyBI b3cgZG8gSSBzdWJ0cmFjdCB0d28gdGltZS9kYXRlcyBhbmQgY2FsY3VsYXRlIHRoZSBob3VycyBh bmQgbWludXRlc2JldHdlZW4/U3RldmUtLSBodHRwczovL21haWwucHl0aG9uLm9yZy9tYWlsbWFu L2xpc3RpbmZvL3B5dGhvbi1saXN0

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Marc Lucke@21:1/5 to Steve GS on Mon Dec 12 17:40:21 2022
    my approach would be to convert your two date/times to seconds from
    epoch - e.g.
    https://www.geeksforgeeks.org/convert-python-datetime-to-epoch/ - then
    subtract the number, divide the resultant by 3600 (hours) & get the
    modulus for minutes.  There's probably a standard function - it should
    be /very/ easy to do.

    - Marc

    On 12/12/2022 5:01 pm, Steve GS wrote:
    How do I subtract two time/dates and calculate the hours and minutes
    between?
    Steve


    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Weatherby,Gerard@21:1/5 to Steve GS on Mon Dec 12 17:49:32 2022
    The difference between two datetime objects is a timedelta object. https://docs.python.org/3/library/datetime.html#timedelta-objects . It has a total_seconds() method.

    This is a simple task, unless one of the datetimes has a time zone specified and the other doesn’t.

    From: Python-list <python-list-bounces+gweatherby=uchc.edu@python.org> on behalf of Marc Lucke <marc@marcsnet.com>
    Date: Monday, December 12, 2022 at 11:37 AM
    To: python-list@python.org <python-list@python.org>
    Subject: Re: Subtracting dates to get hours and minutes
    *** Attention: This is an external email. Use caution responding, opening attachments or clicking on links. ***

    my approach would be to convert your two date/times to seconds from
    epoch - e.g. https://urldefense.com/v3/__https://www.geeksforgeeks.org/convert-python-datetime-to-epoch/__;!!Cn_UX_p3!hBXQeMkZ3QYS6BI0yTHsADseWTXcDXOhKFkg35NnRMicvYQvwLo9c_ihSaTrG60LywsKQm6UNd7mAAYr$<https://urldefense.com/v3/__https:/www.geeksforgeeks.org/convert-
    python-datetime-to-epoch/__;!!Cn_UX_p3!hBXQeMkZ3QYS6BI0yTHsADseWTXcDXOhKFkg35NnRMicvYQvwLo9c_ihSaTrG60LywsKQm6UNd7mAAYr$> - then
    subtract the number, divide the resultant by 3600 (hours) & get the
    modulus for minutes. There's probably a standard function - it should
    be /very/ easy to do.

    - Marc

    On 12/12/2022 5:01 pm, Steve GS wrote:
    How do I subtract two time/dates and calculate the hours and minutes
    between?
    Steve

    -- https://urldefense.com/v3/__https://mail.python.org/mailman/listinfo/python-list__;!!Cn_UX_p3!hBXQeMkZ3QYS6BI0yTHsADseWTXcDXOhKFkg35NnRMicvYQvwLo9c_ihSaTrG60LywsKQm6UNSbh5q0S$<https://urldefense.com/v3/__https:/mail.python.org/mailman/listinfo/python-
    list__;!!Cn_UX_p3!hBXQeMkZ3QYS6BI0yTHsADseWTXcDXOhKFkg35NnRMicvYQvwLo9c_ihSaTrG60LywsKQm6UNSbh5q0S$>

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Gronicus@SGA.Ninja@21:1/5 to All on Tue Dec 13 22:43:35 2022
    As is, Test A works.
    Comment out Test A and uncomment Test B it fails.
    In Test B, I move the data into a variable resulting with the report:
    "TypeError: an integer is required (got type tuple)

    How do I fix this?

    #----------------------------------------------------------------------------- import datetime
    #=================================================
    # Test A Hard coded Date/Time
    Startt = datetime.datetime(2022, 12, 13, 5, 3, 30)
    Stopp = datetime.datetime(2022, 12, 12, 21, 15, 30)

    # =================================================
    # Test B Date/Time data as a variable
    #Startt = (2022, 12, 13, 5, 3, 30)
    #Stopp = (2022, 12, 12, 21, 15, 30)

    #Startt = datetime.datetime(Startt)
    #Stopp = datetime.datetime(Stopp)

    # =================================================
    c = Startt - Stopp
    minutes = c.total_seconds() / 60
    minutes = c.seconds / 60
    hours = 0

    while (minutes > 59):
    minutes = minutes - 60
    hours += 1
    minutes = round(minutes)
    print()
    print (" Hours = <" + str(hours) + ">")
    print (" Minutes = <" + str(minutes) + ">")

    # -----------------------------------------------------------------------------

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Thomas Passin@21:1/5 to Gronicus@SGA.Ninja on Tue Dec 13 23:19:58 2022
    Your problem is that datetime.datetime does not accept a tuple as an
    argument. It expects an integer value for the first argument, but you
    supplied a tuple. In Python, you can use a sequence (e.g., tuple or
    list) the way you want by prefixing it with an asterisk. This causes
    the sequence of items to be treated as individual arguments. So:

    Startt = datetime.datetime(2022, 12, 13, 5, 3, 30)
    st1 = (2022, 12, 13, 5, 3, 30)
    dts1 = datetime.datetime(*st1) # NOT datetime.datetime(st1)
    dts1 == Startt # True

    On 12/13/2022 10:43 PM, Gronicus@SGA.Ninja wrote:
    As is, Test A works.
    Comment out Test A and uncomment Test B it fails.
    In Test B, I move the data into a variable resulting with the report:
    "TypeError: an integer is required (got type tuple)

    How do I fix this?

    #-----------------------------------------------------------------------------
    import datetime
    #=================================================
    # Test A Hard coded Date/Time
    Startt = datetime.datetime(2022, 12, 13, 5, 3, 30)
    Stopp = datetime.datetime(2022, 12, 12, 21, 15, 30)

    # =================================================
    # Test B Date/Time data as a variable
    #Startt = (2022, 12, 13, 5, 3, 30)
    #Stopp = (2022, 12, 12, 21, 15, 30)

    #Startt = datetime.datetime(Startt)
    #Stopp = datetime.datetime(Stopp)

    # =================================================
    c = Startt - Stopp
    minutes = c.total_seconds() / 60
    minutes = c.seconds / 60
    hours = 0

    while (minutes > 59):
    minutes = minutes - 60
    hours += 1
    minutes = round(minutes)
    print()
    print (" Hours = <" + str(hours) + ">")
    print (" Minutes = <" + str(minutes) + ">")

    # -----------------------------------------------------------------------------


    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Gronicus@SGA.Ninja@21:1/5 to Gronicus@SGA.Ninja on Wed Dec 14 00:55:49 2022
    I realized it had something to do with tupilation
    The simple fix is to add the * into the original code.
    Startt = datetime.datetime(*Startt)

    I am not sure what "dts1 == Startt # True" does....

    Thank you.....


    -----Original Message-----
    From: Python-list <python-list-bounces+gronicus=sga.ninja@python.org> On
    Behalf Of Thomas Passin
    Sent: Tuesday, December 13, 2022 11:20 PM
    To: python-list@python.org
    Subject: Re: Subtracting dates to get hours and minutes

    Your problem is that datetime.datetime does not accept a tuple as an
    argument. It expects an integer value for the first argument, but you
    supplied a tuple. In Python, you can use a sequence (e.g., tuple or
    list) the way you want by prefixing it with an asterisk. This causes the sequence of items to be treated as individual arguments. So:

    Startt = datetime.datetime(2022, 12, 13, 5, 3, 30)
    st1 = (2022, 12, 13, 5, 3, 30)
    dts1 = datetime.datetime(*st1) # NOT datetime.datetime(st1)
    dts1 == Startt # True

    On 12/13/2022 10:43 PM, Gronicus@SGA.Ninja wrote:
    As is, Test A works.
    Comment out Test A and uncomment Test B it fails.
    In Test B, I move the data into a variable resulting with the report:
    "TypeError: an integer is required (got type tuple)

    How do I fix this?

    #--------------------------------------------------------------------- --------
    import datetime
    #=================================================
    # Test A Hard coded Date/Time
    Startt = datetime.datetime(2022, 12, 13, 5, 3, 30) Stopp = datetime.datetime(2022, 12, 12, 21, 15, 30)

    # =================================================
    # Test B Date/Time data as a variable
    #Startt = (2022, 12, 13, 5, 3, 30)
    #Stopp = (2022, 12, 12, 21, 15, 30)

    #Startt = datetime.datetime(Startt)
    #Stopp = datetime.datetime(Stopp)

    # =================================================
    c = Startt - Stopp
    minutes = c.total_seconds() / 60
    minutes = c.seconds / 60
    hours = 0

    while (minutes > 59):
    minutes = minutes - 60
    hours += 1
    minutes = round(minutes)
    print()
    print (" Hours = <" + str(hours) + ">")
    print (" Minutes = <" + str(minutes) + ">")

    #
    ---------------------------------------------------------------------- -------


    --
    https://mail.python.org/mailman/listinfo/python-list

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Thomas Passin@21:1/5 to Gronicus@SGA.Ninja on Wed Dec 14 09:30:54 2022
    On 12/14/2022 12:55 AM, Gronicus@SGA.Ninja wrote:
    I realized it had something to do with tupilation
    The simple fix is to add the * into the original code.
    Startt = datetime.datetime(*Startt)

    I am not sure what "dts1 == Startt # True" does....

    It demonstrates that the version with the "*" gives the same result as
    the first expression. That line is not needed by any code, it's just
    there to show you that the proposed expression gives the desired result.

    Thank you.....


    -----Original Message-----
    From: Python-list <python-list-bounces+gronicus=sga.ninja@python.org> On Behalf Of Thomas Passin
    Sent: Tuesday, December 13, 2022 11:20 PM
    To: python-list@python.org
    Subject: Re: Subtracting dates to get hours and minutes

    Your problem is that datetime.datetime does not accept a tuple as an argument. It expects an integer value for the first argument, but you supplied a tuple. In Python, you can use a sequence (e.g., tuple or
    list) the way you want by prefixing it with an asterisk. This causes the sequence of items to be treated as individual arguments. So:

    Startt = datetime.datetime(2022, 12, 13, 5, 3, 30)
    st1 = (2022, 12, 13, 5, 3, 30)
    dts1 = datetime.datetime(*st1) # NOT datetime.datetime(st1)
    dts1 == Startt # True

    On 12/13/2022 10:43 PM, Gronicus@SGA.Ninja wrote:
    As is, Test A works.
    Comment out Test A and uncomment Test B it fails.
    In Test B, I move the data into a variable resulting with the report:
    "TypeError: an integer is required (got type tuple)

    How do I fix this?

    #---------------------------------------------------------------------
    --------
    import datetime
    #=================================================
    # Test A Hard coded Date/Time
    Startt = datetime.datetime(2022, 12, 13, 5, 3, 30) Stopp =
    datetime.datetime(2022, 12, 12, 21, 15, 30)

    # =================================================
    # Test B Date/Time data as a variable
    #Startt = (2022, 12, 13, 5, 3, 30)
    #Stopp = (2022, 12, 12, 21, 15, 30)

    #Startt = datetime.datetime(Startt)
    #Stopp = datetime.datetime(Stopp)

    # =================================================
    c = Startt - Stopp
    minutes = c.total_seconds() / 60
    minutes = c.seconds / 60
    hours = 0

    while (minutes > 59):
    minutes = minutes - 60
    hours += 1
    minutes = round(minutes)
    print()
    print (" Hours = <" + str(hours) + ">")
    print (" Minutes = <" + str(minutes) + ">")

    #
    ----------------------------------------------------------------------
    -------


    --
    https://mail.python.org/mailman/listinfo/python-list


    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Gronicus@SGA.Ninja@21:1/5 to Gronicus@SGA.Ninja on Thu Dec 15 13:14:43 2022
    So far so good , I can now use a variable in datetime.datetime but it only works if I hard-code the time/date information. Now I want to have the code read from a file but I get: TypeError: function takes at most 9 arguments
    (26 given)

    I figure that the structure in the file is incorrect. What should it be? The entry in the file is (2022, 12, 13, 5, 3, 30) but when my program tries to use it I get the error.

    The program is a bit more sophisticated now but here is the update with a sample of the SPECIFICATIONS.txt file: =====================================================================

    # This program compares two Timedate values, subtracts the two and
    # converts the difference to seconds and hours.
    #

    # %A Monday # %a Mon # %B January # %b Jan
    # %d 05 day # %m month as 01 # %Y 2020 # %y 20
    # %H 24 # %I 12 # %M 30 min # %S Seconds

    import time
    import datetime
    from time import gmtime, strftime ##define strftime as time/date right now
    # ======================================================

    def GetSpecByItem(GetThisOne): #get line by item in column 4 - 7
    ItemValue = "--"

    with open("SPECIFICATIONS.txt" , 'r') as infile:
    for lineEQN in infile: # loop to find each line in the file for that
    dose
    if ((lineEQN[4:7]== GetThisOne)):
    ItemValue = lineEQN[30:60].strip() # Just the Data
    return(ItemValue)

    """
    SPECIFICATIONS.txt

    IYf HRB Humalog R Date (2018, 12, 4, 10, 7, 00) ##
    IYf HRG Humulin R Date (2022, 12, 13, 5, 3, 30) ##
    """
    # ====================== Main() ======================================
    print()
    Startt = "404"
    Stopp = "404"

    Answer = "Y"
    Answer = input("Run test A? (" + Answer + ")" )

    if Answer == "Y" or Answer == "y" or Answer == "":
    print()
    print(" Running Test A:")
    # Year Mth Day Hour Min Sec
    Startt = 2018, 12, 4, 10, 7, 00
    Stopp = 2022, 12, 12, 1, 15, 30
    NowTime = 2022, 12, 14, 21, 15, 30
    else:
    print(" Running Test B:")
    Startt = GetSpecByItem("HRG")
    Stopp = GetSpecByItem("HRB")
    NowTime = strftime("(%Y, %m, %d, %H, %M, %S)")

    print()
    print("55 NowTime = " + str(NowTime))
    print("56 Startt = " + str(Startt))
    print("57 Stopp = " + str(Stopp))
    print()

    NowTime = datetime.datetime(*NowTime)
    Startt = datetime.datetime(*Startt)
    Stopp = datetime.datetime(*Stopp)

    #Start == Startt # True"
    #print("Startt test = " + Start)
    # =================================================
    print()
    c = NowTime - Stopp
    minutes = c.total_seconds() / 60
    minutes = c.seconds / 60
    hours = 0

    while (minutes > 59):
    minutes = minutes - 60
    hours += 1
    minutes = round(minutes)
    print ("77 Hours = <" + str(hours) + ">")
    print ("78 Minutes = <" + str(minutes) + ">")
    if hours > 7:
    print(" Time to inject Humulin R u500.")

    pause = input("Pause")
    # ======================================================


    -----Original Message-----
    From: Python-list <python-list-bounces+gronicus=sga.ninja@python.org> On
    Behalf Of Thomas Passin
    Sent: Tuesday, December 13, 2022 11:20 PM
    To: python-list@python.org
    Subject: Re: Subtracting dates to get hours and minutes

    Your problem is that datetime.datetime does not accept a tuple as an
    argument. It expects an integer value for the first argument, but you
    supplied a tuple. In Python, you can use a sequence (e.g., tuple or
    list) the way you want by prefixing it with an asterisk. This causes the sequence of items to be treated as individual arguments. So:

    Startt = datetime.datetime(2022, 12, 13, 5, 3, 30)
    st1 = (2022, 12, 13, 5, 3, 30)
    dts1 = datetime.datetime(*st1) # NOT datetime.datetime(st1)
    dts1 == Startt # True

    On 12/13/2022 10:43 PM, Gronicus@SGA.Ninja wrote:
    As is, Test A works.
    Comment out Test A and uncomment Test B it fails.
    In Test B, I move the data into a variable resulting with the report:
    "TypeError: an integer is required (got type tuple)

    How do I fix this?

    #--------------------------------------------------------------------- --------
    import datetime
    #=================================================
    # Test A Hard coded Date/Time
    Startt = datetime.datetime(2022, 12, 13, 5, 3, 30) Stopp = datetime.datetime(2022, 12, 12, 21, 15, 30)

    # =================================================
    # Test B Date/Time data as a variable
    #Startt = (2022, 12, 13, 5, 3, 30)
    #Stopp = (2022, 12, 12, 21, 15, 30)

    #Startt = datetime.datetime(Startt)
    #Stopp = datetime.datetime(Stopp)

    # =================================================
    c = Startt - Stopp
    minutes = c.total_seconds() / 60
    minutes = c.seconds / 60
    hours = 0

    while (minutes > 59):
    minutes = minutes - 60
    hours += 1
    minutes = round(minutes)
    print()
    print (" Hours = <" + str(hours) + ">")
    print (" Minutes = <" + str(minutes) + ">")

    #
    ---------------------------------------------------------------------- -------


    --
    https://mail.python.org/mailman/listinfo/python-list

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From MRAB@21:1/5 to Gronicus@SGA.Ninja on Thu Dec 15 19:27:46 2022
    On 2022-12-15 18:14, Gronicus@SGA.Ninja wrote:
    So far so good , I can now use a variable in datetime.datetime but it only works if I hard-code the time/date information. Now I want to have the code read from a file but I get: TypeError: function takes at most 9 arguments
    (26 given)

    I figure that the structure in the file is incorrect. What should it be? The entry in the file is (2022, 12, 13, 5, 3, 30) but when my program tries to use it I get the error.

    The program is a bit more sophisticated now but here is the update with a sample of the SPECIFICATIONS.txt file: =====================================================================

    # This program compares two Timedate values, subtracts the two and
    # converts the difference to seconds and hours.
    #

    # %A Monday # %a Mon # %B January # %b Jan
    # %d 05 day # %m month as 01 # %Y 2020 # %y 20
    # %H 24 # %I 12 # %M 30 min # %S Seconds

    import time
    import datetime
    from time import gmtime, strftime ##define strftime as time/date right now
    # ======================================================

    def GetSpecByItem(GetThisOne): #get line by item in column 4 - 7
    ItemValue = "--"

    with open("SPECIFICATIONS.txt" , 'r') as infile:
    for lineEQN in infile: # loop to find each line in the file for that dose
    if ((lineEQN[4:7]== GetThisOne)):

    You don't need the parentheses, and certainly 2 pairs of them!

    ItemValue = lineEQN[30:60].strip() # Just the Data
    return(ItemValue)

    You're returning a _string_.

    I suggest using 'literal_eval' from the 'ast' module to convert the
    string safely into a tuple.

    However, if the 'for' loop fails to match a line, the function will
    return "--", which won't be of any use later on unless you check for it specifically and, say, report an error to the user.


    """
    SPECIFICATIONS.txt

    IYf HRB Humalog R Date (2018, 12, 4, 10, 7, 00) ##
    IYf HRG Humulin R Date (2022, 12, 13, 5, 3, 30) ##
    """
    # ====================== Main() ====================================== print()
    Startt = "404"
    Stopp = "404"

    Answer = "Y"
    Answer = input("Run test A? (" + Answer + ")" )

    if Answer == "Y" or Answer == "y" or Answer == "":
    print()
    print(" Running Test A:")
    # Year Mth Day Hour Min Sec
    Startt = 2018, 12, 4, 10, 7, 00
    Stopp = 2022, 12, 12, 1, 15, 30
    NowTime = 2022, 12, 14, 21, 15, 30

    'Startt' and 'Stopp' here are tuples.

    else:
    print(" Running Test B:")
    Startt = GetSpecByItem("HRG")
    Stopp = GetSpecByItem("HRB")

    'Startt' and 'Stopp' here are _strings_.

    NowTime = strftime("(%Y, %m, %d, %H, %M, %S)")

    print()
    print("55 NowTime = " + str(NowTime))
    print("56 Startt = " + str(Startt))
    print("57 Stopp = " + str(Stopp))
    print()

    NowTime = datetime.datetime(*NowTime)
    Startt = datetime.datetime(*Startt)
    Stopp = datetime.datetime(*Stopp)

    These will work if 'Startt' and 'Stopp' are tuples, but not if they're
    strings. In the latter case, you're effectively passing multiple single-characters strings into 'datetime'.

    #Start == Startt # True"
    #print("Startt test = " + Start)
    # =================================================
    print()
    c = NowTime - Stopp
    minutes = c.total_seconds() / 60
    minutes = c.seconds / 60
    hours = 0

    while (minutes > 59):
    minutes = minutes - 60
    hours += 1
    minutes = round(minutes)
    print ("77 Hours = <" + str(hours) + ">")
    print ("78 Minutes = <" + str(minutes) + ">")
    if hours > 7:
    print(" Time to inject Humulin R u500.")

    pause = input("Pause")
    # ======================================================

    -----Original Message-----
    From: Python-list <python-list-bounces+gronicus=sga.ninja@python.org> On Behalf Of Thomas Passin
    Sent: Tuesday, December 13, 2022 11:20 PM
    To: python-list@python.org
    Subject: Re: Subtracting dates to get hours and minutes

    Your problem is that datetime.datetime does not accept a tuple as an argument. It expects an integer value for the first argument, but you supplied a tuple. In Python, you can use a sequence (e.g., tuple or
    list) the way you want by prefixing it with an asterisk. This causes the sequence of items to be treated as individual arguments. So:

    Startt = datetime.datetime(2022, 12, 13, 5, 3, 30)
    st1 = (2022, 12, 13, 5, 3, 30)
    dts1 = datetime.datetime(*st1) # NOT datetime.datetime(st1)
    dts1 == Startt # True

    On 12/13/2022 10:43 PM, Gronicus@SGA.Ninja wrote:
    As is, Test A works.
    Comment out Test A and uncomment Test B it fails.
    In Test B, I move the data into a variable resulting with the report:
    "TypeError: an integer is required (got type tuple)

    How do I fix this?

    #---------------------------------------------------------------------
    --------
    import datetime
    #=================================================
    # Test A Hard coded Date/Time
    Startt = datetime.datetime(2022, 12, 13, 5, 3, 30) Stopp =
    datetime.datetime(2022, 12, 12, 21, 15, 30)

    # =================================================
    # Test B Date/Time data as a variable
    #Startt = (2022, 12, 13, 5, 3, 30)
    #Stopp = (2022, 12, 12, 21, 15, 30)

    #Startt = datetime.datetime(Startt)
    #Stopp = datetime.datetime(Stopp)

    # =================================================
    c = Startt - Stopp
    minutes = c.total_seconds() / 60
    minutes = c.seconds / 60
    hours = 0

    while (minutes > 59):
    minutes = minutes - 60
    hours += 1
    minutes = round(minutes)
    print()
    print (" Hours = <" + str(hours) + ">")
    print (" Minutes = <" + str(minutes) + ">")

    #
    ----------------------------------------------------------------------
    -------


    --
    https://mail.python.org/mailman/listinfo/python-list


    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Thomas Passin@21:1/5 to Gronicus@SGA.Ninja on Thu Dec 15 13:56:05 2022
    It's hard to be sure from what you have offered, but I suspect that you
    are taking the string "(2022, 12, 13, 5, 3, 30)" from the file and
    using it as is. When you feed that in as a starred argument, the string
    gets treated as a sequence where each item is a character in the string.
    Your example contains 26 characters, which matches the error message,
    so that's probably what is going on.

    You need to convert the string into the correct integers, because is the datetime function expects to get integers, not strings. It isn't going
    to work with a string that looks like a tuple when it is printed.

    Here is one way you could do this. From the input file, extract the
    string. Call it dstr. Then you have to get rid of the parentheses and
    separate out each item so you can convert it into an integer. So:

    items = dstr[1:-2].split(',') # This creates a list of strings.
    # print(items) --> ['2022', ' 12', ' 13', ' 5', ' 3', ' 3']

    # Create a tuple of integers from the string items
    seq = (int(n) for n in items)
    # or make it a list instead: seq = [int(n) for n in items]

    # And here is the datetime object you wanted
    d1 = datetime.datetime(*seq)


    On 12/15/2022 1:14 PM, Gronicus@SGA.Ninja wrote:
    So far so good , I can now use a variable in datetime.datetime but it only works if I hard-code the time/date information. Now I want to have the code read from a file but I get: TypeError: function takes at most 9 arguments
    (26 given)

    I figure that the structure in the file is incorrect. What should it be? The entry in the file is (2022, 12, 13, 5, 3, 30) but when my program tries to use it I get the error.

    The program is a bit more sophisticated now but here is the update with a sample of the SPECIFICATIONS.txt file: =====================================================================

    # This program compares two Timedate values, subtracts the two and
    # converts the difference to seconds and hours.
    #

    # %A Monday # %a Mon # %B January # %b Jan
    # %d 05 day # %m month as 01 # %Y 2020 # %y 20
    # %H 24 # %I 12 # %M 30 min # %S Seconds

    import time
    import datetime
    from time import gmtime, strftime ##define strftime as time/date right now
    # ======================================================

    def GetSpecByItem(GetThisOne): #get line by item in column 4 - 7
    ItemValue = "--"

    with open("SPECIFICATIONS.txt" , 'r') as infile:
    for lineEQN in infile: # loop to find each line in the file for that dose
    if ((lineEQN[4:7]== GetThisOne)):
    ItemValue = lineEQN[30:60].strip() # Just the Data
    return(ItemValue)

    """
    SPECIFICATIONS.txt

    IYf HRB Humalog R Date (2018, 12, 4, 10, 7, 00) ##
    IYf HRG Humulin R Date (2022, 12, 13, 5, 3, 30) ##
    """
    # ====================== Main() ====================================== print()
    Startt = "404"
    Stopp = "404"

    Answer = "Y"
    Answer = input("Run test A? (" + Answer + ")" )

    if Answer == "Y" or Answer == "y" or Answer == "":
    print()
    print(" Running Test A:")
    # Year Mth Day Hour Min Sec
    Startt = 2018, 12, 4, 10, 7, 00
    Stopp = 2022, 12, 12, 1, 15, 30
    NowTime = 2022, 12, 14, 21, 15, 30
    else:
    print(" Running Test B:")
    Startt = GetSpecByItem("HRG")
    Stopp = GetSpecByItem("HRB")
    NowTime = strftime("(%Y, %m, %d, %H, %M, %S)")

    print()
    print("55 NowTime = " + str(NowTime))
    print("56 Startt = " + str(Startt))
    print("57 Stopp = " + str(Stopp))
    print()

    NowTime = datetime.datetime(*NowTime)
    Startt = datetime.datetime(*Startt)
    Stopp = datetime.datetime(*Stopp)

    #Start == Startt # True"
    #print("Startt test = " + Start)
    # =================================================
    print()
    c = NowTime - Stopp
    minutes = c.total_seconds() / 60
    minutes = c.seconds / 60
    hours = 0

    while (minutes > 59):
    minutes = minutes - 60
    hours += 1
    minutes = round(minutes)
    print ("77 Hours = <" + str(hours) + ">")
    print ("78 Minutes = <" + str(minutes) + ">")
    if hours > 7:
    print(" Time to inject Humulin R u500.")

    pause = input("Pause")
    # ======================================================


    -----Original Message-----
    From: Python-list <python-list-bounces+gronicus=sga.ninja@python.org> On Behalf Of Thomas Passin
    Sent: Tuesday, December 13, 2022 11:20 PM
    To: python-list@python.org
    Subject: Re: Subtracting dates to get hours and minutes

    Your problem is that datetime.datetime does not accept a tuple as an argument. It expects an integer value for the first argument, but you supplied a tuple. In Python, you can use a sequence (e.g., tuple or
    list) the way you want by prefixing it with an asterisk. This causes the sequence of items to be treated as individual arguments. So:

    Startt = datetime.datetime(2022, 12, 13, 5, 3, 30)
    st1 = (2022, 12, 13, 5, 3, 30)
    dts1 = datetime.datetime(*st1) # NOT datetime.datetime(st1)
    dts1 == Startt # True

    On 12/13/2022 10:43 PM, Gronicus@SGA.Ninja wrote:
    As is, Test A works.
    Comment out Test A and uncomment Test B it fails.
    In Test B, I move the data into a variable resulting with the report:
    "TypeError: an integer is required (got type tuple)

    How do I fix this?

    #---------------------------------------------------------------------
    --------
    import datetime
    #=================================================
    # Test A Hard coded Date/Time
    Startt = datetime.datetime(2022, 12, 13, 5, 3, 30) Stopp =
    datetime.datetime(2022, 12, 12, 21, 15, 30)

    # =================================================
    # Test B Date/Time data as a variable
    #Startt = (2022, 12, 13, 5, 3, 30)
    #Stopp = (2022, 12, 12, 21, 15, 30)

    #Startt = datetime.datetime(Startt)
    #Stopp = datetime.datetime(Stopp)

    # =================================================
    c = Startt - Stopp
    minutes = c.total_seconds() / 60
    minutes = c.seconds / 60
    hours = 0

    while (minutes > 59):
    minutes = minutes - 60
    hours += 1
    minutes = round(minutes)
    print()
    print (" Hours = <" + str(hours) + ">")
    print (" Minutes = <" + str(minutes) + ">")

    #
    ----------------------------------------------------------------------
    -------


    --
    https://mail.python.org/mailman/listinfo/python-list


    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Gronicus@SGA.Ninja@21:1/5 to All on Thu Dec 15 17:00:11 2022
    Yes, it works like a charm. On the tupility of it all.
    Special thanks for the explanation too…..



    Now that the code no longer produces the errors, I see that the year and month not included in the calculation? How do I fix this?



    From: anthony.flury <anthony.flury@btinternet.com>
    Sent: Thursday, December 15, 2022 1:47 PM
    To: Gronicus@SGA.Ninja
    Subject: RE: Subtracting dates to get hours and minutes



    What is likely happening is that when you read the data from the file you are not reading a tuple, you are reading a 26 charcter string.

    You have to convert that string into a tuple - the easiest way will be somthing like this :



    timet = tuple(int(x.strip()) for x in timestring[1:-1].split(','))



    where timestring is the data you get from the file

    The [1:-1] removes the () from the data

    The .split(",") method creates a temporary list from the remaining string breaking the string where there are commas

    The x.strip() removes spaces from each item in the temporary list.



    Note that the * unpack operator doesn't just unpack tuples, it works on an iterable, so when you read the data from the file currently, and then use * on it, it will pass 26 separate characters to the function.





    ------ Original Message ------
    From: Gronicus@SGA.Ninja <mailto:Gronicus@SGA.Ninja>
    To: "'Thomas Passin'" <list1@tompassin.net <mailto:list1@tompassin.net> >; python-list@python.org <mailto:python-list@python.org>
    Sent: Thursday, 15 Dec, 22 At 18:14
    Subject: RE: Subtracting dates to get hours and minutes

    So far so good , I can now use a variable in datetime.datetime but it only works if I hard-code the time/date information. Now I want to have the code read from a file but I get: TypeError: function takes at most 9 arguments
    (26 given)

    I figure that the structure in the file is incorrect. What should it be? The entry in the file is (2022, 12, 13, 5, 3, 30) but when my program tries to
    use it I get the error.

    The program is a bit more sophisticated now but here is the update with a sample of the SPECIFICATIONS.txt file: =====================================================================

    # This program compares two Timedate values, subtracts the two and
    # converts the difference to seconds and hours.
    #

    # %A Monday # %a Mon # %B January # %b Jan
    # %d 05 day # %m month as 01 # %Y 2020 # %y 20
    # %H 24 # %I 12 # %M 30 min # %S Seconds

    import time
    import datetime
    from time import gmtime, strftime ##define strftime as time/date right now
    # ======================================================

    def GetSpecByItem(GetThisOne): #get line by item in column 4 - 7
    ItemValue = "--"

    with open("SPECIFICATIONS.txt" , 'r') as infile:
    for lineEQN in infile: # loop to find each line in the file for that
    dose
    if ((lineEQN[4:7]== GetThisOne)):
    ItemValue = lineEQN[30:60].strip() # Just the Data
    return(ItemValue)

    """
    SPECIFICATIONS.txt

    IYf HRB Humalog R Date (2018, 12, 4, 10, 7, 00) ##
    IYf HRG Humulin R Date (2022, 12, 13, 5, 3, 30) ##
    """
    # ====================== Main() ======================================
    print()
    Startt = "404"
    Stopp = "404"

    Answer = "Y"
    Answer = input("Run test A? (" + Answer + ")" )

    if Answer == "Y" or Answer == "y" or Answer == "":
    print()
    print(" Running Test A:")
    # Year Mth Day Hour Min Sec
    Startt = 2018, 12, 4, 10, 7, 00
    Stopp = 2022, 12, 12, 1, 15, 30
    NowTime = 2022, 12, 14, 21, 15, 30
    else:
    print(" Running Test B:")
    Startt = GetSpecByItem("HRG")
    Stopp = GetSpecByItem("HRB")
    NowTime = strftime("(%Y, %m, %d, %H, %M, %S)")

    print()
    print("55 NowTime = " + str(NowTime))
    print("56 Startt = " + str(Startt))
    print("57 Stopp = " + str(Stopp))
    print()

    NowTime = datetime.datetime(*NowTime)
    Startt = datetime.datetime(*Startt)
    Stopp = datetime.datetime(*Stopp)

    #Start == Startt # True"
    #print("Startt test = " + Start)
    # =================================================
    print()
    c = NowTime - Stopp
    minutes = c.total_seconds() / 60
    minutes = c.seconds / 60
    hours = 0

    while (minutes > 59):
    minutes = minutes - 60
    hours += 1
    minutes = round(minutes)
    print ("77 Hours = <" + str(hours) + ">")
    print ("78 Minutes = <" + str(minutes) + ">")
    if hours > 7:
    print(" Time to inject Humulin R u500.")

    pause = input("Pause")
    # ======================================================


    -----Original Message-----
    From: Python-list <python-list-bounces+gronicus=sga.ninja@python.org <mailto:python-list-bounces+gronicus=sga.ninja@python.org> > On
    Behalf Of Thomas Passin
    Sent: Tuesday, December 13, 2022 11:20 PM
    To: python-list@python.org <mailto:python-list@python.org>
    Subject: Re: Subtracting dates to get hours and minutes

    Your problem is that datetime.datetime does not accept a tuple as an
    argument. It expects an integer value for the first argument, but you
    supplied a tuple. In Python, you can use a sequence (e.g., tuple or
    list) the way you want by prefixing it with an asterisk. This causes the sequence of items to be treated as individual arguments. So:

    Startt = datetime.datetime(2022, 12, 13, 5, 3, 30)
    st1 = (2022, 12, 13, 5, 3, 30)
    dts1 = datetime.datetime(*st1) # NOT datetime.datetime(st1)
    dts1 == Startt # True

    On 12/13/2022 10:43 PM, Gronicus@SGA.Ninja <mailto:Gronicus@SGA.Ninja> wrote:


    As is, Test A works.
    Comment out Test A and uncomment Test B it fails.
    In Test B, I move the data into a variable resulting with the report: "TypeError: an integer is required (got type tuple)

    How do I fix this?

    #---------------------------------------------------------------------
    --------
    import datetime
    #=================================================
    # Test A Hard coded Date/Time
    Startt = datetime.datetime(2022, 12, 13, 5, 3, 30) Stopp = datetime.datetime(2022, 12, 12, 21, 15, 30)

    # =================================================
    # Test B Date/Time data as a variable
    #Startt = (2022, 12, 13, 5, 3, 30)
    #Stopp = (2022, 12, 12, 21, 15, 30)

    #Startt = datetime.datetime(Startt)
    #Stopp = datetime.datetime(Stopp)

    # =================================================
    c = Startt - Stopp
    minutes = c.total_seconds() / 60
    minutes = c.seconds / 60
    hours = 0

    while (minutes > 59):
    minutes = minutes - 60
    hours += 1
    minutes = round(minutes)
    print()
    print (" Hours = <" + str(hours) + ">")
    print (" Minutes = <" + str(minutes) + ">")

    #
    ----------------------------------------------------------------------
    -------


    --
    https://mail.python.org/mailman/listinfo/python-list

    --
    https://mail.python.org/mailman/listinfo/python-list

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Gronicus@SGA.Ninja@21:1/5 to All on Thu Dec 15 17:49:23 2022
    Yes, it works like a charm. On the tupility of it all.
    Special thanks for the explanation too…..



    (Originally asked but I found the errors. All is working)

    Now that the code no longer produces the errors, I see that the year and month not included in the calculation? How do I fix this?



    From: anthony.flury <anthony.flury@btinternet.com>
    Sent: Thursday, December 15, 2022 1:47 PM
    To: Gronicus@SGA.Ninja
    Subject: RE: Subtracting dates to get hours and minutes



    What is likely happening is that when you read the data from the file you are not reading a tuple, you are reading a 26 charcter string.

    You have to convert that string into a tuple - the easiest way will be somthing like this :



    timet = tuple(int(x.strip()) for x in timestring[1:-1].split(','))



    where timestring is the data you get from the file

    The [1:-1] removes the () from the data

    The .split(",") method creates a temporary list from the remaining string breaking the string where there are commas

    The x.strip() removes spaces from each item in the temporary list.



    Note that the * unpack operator doesn't just unpack tuples, it works on an iterable, so when you read the data from the file currently, and then use * on it, it will pass 26 separate characters to the function.





    ------ Original Message ------
    From: Gronicus@SGA.Ninja <mailto:Gronicus@SGA.Ninja>
    To: "'Thomas Passin'" <list1@tompassin.net <mailto:list1@tompassin.net> >; python-list@python.org <mailto:python-list@python.org>
    Sent: Thursday, 15 Dec, 22 At 18:14
    Subject: RE: Subtracting dates to get hours and minutes

    So far so good , I can now use a variable in datetime.datetime but it only works if I hard-code the time/date information. Now I want to have the code read from a file but I get: TypeError: function takes at most 9 arguments
    (26 given)

    I figure that the structure in the file is incorrect. What should it be? The entry in the file is (2022, 12, 13, 5, 3, 30) but when my program tries to
    use it I get the error.

    The program is a bit more sophisticated now but here is the update with a sample of the SPECIFICATIONS.txt file: =====================================================================

    # This program compares two Timedate values, subtracts the two and
    # converts the difference to seconds and hours.
    #

    # %A Monday # %a Mon # %B January # %b Jan
    # %d 05 day # %m month as 01 # %Y 2020 # %y 20
    # %H 24 # %I 12 # %M 30 min # %S Seconds

    import time
    import datetime
    from time import gmtime, strftime ##define strftime as time/date right now
    # ======================================================

    def GetSpecByItem(GetThisOne): #get line by item in column 4 - 7
    ItemValue = "--"

    with open("SPECIFICATIONS.txt" , 'r') as infile:
    for lineEQN in infile: # loop to find each line in the file for that
    dose
    if ((lineEQN[4:7]== GetThisOne)):
    ItemValue = lineEQN[30:60].strip() # Just the Data
    return(ItemValue)

    """
    SPECIFICATIONS.txt

    IYf HRB Humalog R Date (2018, 12, 4, 10, 7, 00) ##
    IYf HRG Humulin R Date (2022, 12, 13, 5, 3, 30) ##
    """
    # ====================== Main() ======================================
    print()
    Startt = "404"
    Stopp = "404"

    Answer = "Y"
    Answer = input("Run test A? (" + Answer + ")" )

    if Answer == "Y" or Answer == "y" or Answer == "":
    print()
    print(" Running Test A:")
    # Year Mth Day Hour Min Sec
    Startt = 2018, 12, 4, 10, 7, 00
    Stopp = 2022, 12, 12, 1, 15, 30
    NowTime = 2022, 12, 14, 21, 15, 30
    else:
    print(" Running Test B:")
    Startt = GetSpecByItem("HRG")
    Stopp = GetSpecByItem("HRB")
    NowTime = strftime("(%Y, %m, %d, %H, %M, %S)")

    print()
    print("55 NowTime = " + str(NowTime))
    print("56 Startt = " + str(Startt))
    print("57 Stopp = " + str(Stopp))
    print()

    NowTime = datetime.datetime(*NowTime)
    Startt = datetime.datetime(*Startt)
    Stopp = datetime.datetime(*Stopp)

    #Start == Startt # True"
    #print("Startt test = " + Start)
    # =================================================
    print()
    c = NowTime - Stopp
    minutes = c.total_seconds() / 60
    minutes = c.seconds / 60
    hours = 0

    while (minutes > 59):
    minutes = minutes - 60
    hours += 1
    minutes = round(minutes)
    print ("77 Hours = <" + str(hours) + ">")
    print ("78 Minutes = <" + str(minutes) + ">")
    if hours > 7:
    print(" Time to inject Humulin R u500.")

    pause = input("Pause")
    # ======================================================


    -----Original Message-----
    From: Python-list <python-list-bounces+gronicus=sga.ninja@python.org <mailto:python-list-bounces+gronicus=sga.ninja@python.org> > On
    Behalf Of Thomas Passin
    Sent: Tuesday, December 13, 2022 11:20 PM
    To: python-list@python.org <mailto:python-list@python.org>
    Subject: Re: Subtracting dates to get hours and minutes

    Your problem is that datetime.datetime does not accept a tuple as an
    argument. It expects an integer value for the first argument, but you
    supplied a tuple. In Python, you can use a sequence (e.g., tuple or
    list) the way you want by prefixing it with an asterisk. This causes the sequence of items to be treated as individual arguments. So:

    Startt = datetime.datetime(2022, 12, 13, 5, 3, 30)
    st1 = (2022, 12, 13, 5, 3, 30)
    dts1 = datetime.datetime(*st1) # NOT datetime.datetime(st1)
    dts1 == Startt # True

    On 12/13/2022 10:43 PM, Gronicus@SGA.Ninja <mailto:Gronicus@SGA.Ninja> wrote:


    As is, Test A works.
    Comment out Test A and uncomment Test B it fails.
    In Test B, I move the data into a variable resulting with the report: "TypeError: an integer is required (got type tuple)

    How do I fix this?

    #---------------------------------------------------------------------
    --------
    import datetime
    #=================================================
    # Test A Hard coded Date/Time
    Startt = datetime.datetime(2022, 12, 13, 5, 3, 30) Stopp = datetime.datetime(2022, 12, 12, 21, 15, 30)

    # =================================================
    # Test B Date/Time data as a variable
    #Startt = (2022, 12, 13, 5, 3, 30)
    #Stopp = (2022, 12, 12, 21, 15, 30)

    #Startt = datetime.datetime(Startt)
    #Stopp = datetime.datetime(Stopp)

    # =================================================
    c = Startt - Stopp
    minutes = c.total_seconds() / 60
    minutes = c.seconds / 60
    hours = 0

    while (minutes > 59):
    minutes = minutes - 60
    hours += 1
    minutes = round(minutes)
    print()
    print (" Hours = <" + str(hours) + ">")
    print (" Minutes = <" + str(minutes) + ">")

    #
    ----------------------------------------------------------------------
    -------


    --
    https://mail.python.org/mailman/listinfo/python-list

    --
    https://mail.python.org/mailman/listinfo/python-list

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Weatherby,Gerard@21:1/5 to All on Thu Dec 15 22:22:44 2022
    Not sure what you mean:

    x = datetime.datetime(year=2018,month=12,day=4,hour=10)
    y = datetime.datetime(year=2022,month=12,day=13,hour=5)
    print(x -y)


    -1470 days, 5:00:00

    If you want to display years, (x-y).days /365

    From: Python-list <python-list-bounces+gweatherby=uchc.edu@python.org> on behalf of Gronicus@SGA.Ninja <Gronicus@SGA.Ninja>
    Date: Thursday, December 15, 2022 at 5:02 PM
    To: 'anthony.flury' <anthony.flury@btinternet.com>, python-list@python.org <python-list@python.org>
    Subject: RE: Subtracting dates to get hours and minutes
    *** Attention: This is an external email. Use caution responding, opening attachments or clicking on links. ***

    Yes, it works like a charm. On the tupility of it all.
    Special thanks for the explanation too…..



    Now that the code no longer produces the errors, I see that the year and month not included in the calculation? How do I fix this?



    From: anthony.flury <anthony.flury@btinternet.com>
    Sent: Thursday, December 15, 2022 1:47 PM
    To: Gronicus@SGA.Ninja
    Subject: RE: Subtracting dates to get hours and minutes



    What is likely happening is that when you read the data from the file you are not reading a tuple, you are reading a 26 charcter string.

    You have to convert that string into a tuple - the easiest way will be somthing like this :



    timet = tuple(int(x.strip()) for x in timestring[1:-1].split(','))



    where timestring is the data you get from the file

    The [1:-1] removes the () from the data

    The .split(",") method creates a temporary list from the remaining string breaking the string where there are commas

    The x.strip() removes spaces from each item in the temporary list.



    Note that the * unpack operator doesn't just unpack tuples, it works on an iterable, so when you read the data from the file currently, and then use * on it, it will pass 26 separate characters to the function.





    ------ Original Message ------
    From: Gronicus@SGA.Ninja <mailto:Gronicus@SGA.Ninja>
    To: "'Thomas Passin'" <list1@tompassin.net <mailto:list1@tompassin.net> >; python-list@python.org <mailto:python-list@python.org>
    Sent: Thursday, 15 Dec, 22 At 18:14
    Subject: RE: Subtracting dates to get hours and minutes

    So far so good , I can now use a variable in datetime.datetime but it only works if I hard-code the time/date information. Now I want to have the code read from a file but I get: TypeError: function takes at most 9 arguments
    (26 given)

    I figure that the structure in the file is incorrect. What should it be? The entry in the file is (2022, 12, 13, 5, 3, 30) but when my program tries to
    use it I get the error.

    The program is a bit more sophisticated now but here is the update with a sample of the SPECIFICATIONS.txt file: =====================================================================

    # This program compares two Timedate values, subtracts the two and
    # converts the difference to seconds and hours.
    #

    # %A Monday # %a Mon # %B January # %b Jan
    # %d 05 day # %m month as 01 # %Y 2020 # %y 20
    # %H 24 # %I 12 # %M 30 min # %S Seconds

    import time
    import datetime
    from time import gmtime, strftime ##define strftime as time/date right now
    # ======================================================

    def GetSpecByItem(GetThisOne): #get line by item in column 4 - 7
    ItemValue = "--"

    with open("SPECIFICATIONS.txt" , 'r') as infile:
    for lineEQN in infile: # loop to find each line in the file for that
    dose
    if ((lineEQN[4:7]== GetThisOne)):
    ItemValue = lineEQN[30:60].strip() # Just the Data
    return(ItemValue)

    """
    SPECIFICATIONS.txt

    IYf HRB Humalog R Date (2018, 12, 4, 10, 7, 00) ##
    IYf HRG Humulin R Date (2022, 12, 13, 5, 3, 30) ##
    """
    # ====================== Main() ======================================
    print()
    Startt = "404"
    Stopp = "404"

    Answer = "Y"
    Answer = input("Run test A? (" + Answer + ")" )

    if Answer == "Y" or Answer == "y" or Answer == "":
    print()
    print(" Running Test A:")
    # Year Mth Day Hour Min Sec
    Startt = 2018, 12, 4, 10, 7, 00
    Stopp = 2022, 12, 12, 1, 15, 30
    NowTime = 2022, 12, 14, 21, 15, 30
    else:
    print(" Running Test B:")
    Startt = GetSpecByItem("HRG")
    Stopp = GetSpecByItem("HRB")
    NowTime = strftime("(%Y, %m, %d, %H, %M, %S)")

    print()
    print("55 NowTime = " + str(NowTime))
    print("56 Startt = " + str(Startt))
    print("57 Stopp = " + str(Stopp))
    print()

    NowTime = datetime.datetime(*NowTime)
    Startt = datetime.datetime(*Startt)
    Stopp = datetime.datetime(*Stopp)

    #Start == Startt # True"
    #print("Startt test = " + Start)
    # =================================================
    print()
    c = NowTime - Stopp
    minutes = c.total_seconds() / 60
    minutes = c.seconds / 60
    hours = 0

    while (minutes > 59):
    minutes = minutes - 60
    hours += 1
    minutes = round(minutes)
    print ("77 Hours = <" + str(hours) + ">")
    print ("78 Minutes = <" + str(minutes) + ">")
    if hours > 7:
    print(" Time to inject Humulin R u500.")

    pause = input("Pause")
    # ======================================================


    -----Original Message-----
    From: Python-list <python-list-bounces+gronicus=sga.ninja@python.org <mailto:python-list-bounces+gronicus=sga.ninja@python.org> > On
    Behalf Of Thomas Passin
    Sent: Tuesday, December 13, 2022 11:20 PM
    To: python-list@python.org <mailto:python-list@python.org>
    Subject: Re: Subtracting dates to get hours and minutes

    Your problem is that datetime.datetime does not accept a tuple as an
    argument. It expects an integer value for the first argument, but you
    supplied a tuple. In Python, you can use a sequence (e.g., tuple or
    list) the way you want by prefixing it with an asterisk. This causes the sequence of items to be treated as individual arguments. So:

    Startt = datetime.datetime(2022, 12, 13, 5, 3, 30)
    st1 = (2022, 12, 13, 5, 3, 30)
    dts1 = datetime.datetime(*st1) # NOT datetime.datetime(st1)
    dts1 == Startt # True

    On 12/13/2022 10:43 PM, Gronicus@SGA.Ninja <mailto:Gronicus@SGA.Ninja> wrote:


    As is, Test A works.
    Comment out Test A and uncomment Test B it fails.
    In Test B, I move the data into a variable resulting with the report: "TypeError: an integer is required (got type tuple)

    How do I fix this?

    #---------------------------------------------------------------------
    --------
    import datetime
    #=================================================
    # Test A Hard coded Date/Time
    Startt = datetime.datetime(2022, 12, 13, 5, 3, 30) Stopp = datetime.datetime(2022, 12, 12, 21, 15, 30)

    # =================================================
    # Test B Date/Time data as a variable
    #Startt = (2022, 12, 13, 5, 3, 30)
    #Stopp = (2022, 12, 12, 21, 15, 30)

    #Startt = datetime.datetime(Startt)
    #Stopp = datetime.datetime(Stopp)

    # =================================================
    c = Startt - Stopp
    minutes = c.total_seconds() / 60
    minutes = c.seconds / 60
    hours = 0

    while (minutes > 59):
    minutes = minutes - 60
    hours += 1
    minutes = round(minutes)
    print()
    print (" Hours = <" + str(hours) + ">")
    print (" Minutes = <" + str(minutes) + ">")

    #
    ----------------------------------------------------------------------
    -------


    -- https://urldefense.com/v3/__https://mail.python.org/mailman/listinfo/python-list__;!!Cn_UX_p3!g11w53LvI3sz4DsypU-K7satSGvJqZDO1QO9M6Q6Tl3HmndPRIRrkNdzq4_ZJbTiq68dzN535TH75Ks0junwPQ$<https://urldefense.com/v3/__https:/mail.python.org/mailman/listinfo/
    python-list__;!!Cn_UX_p3!g11w53LvI3sz4DsypU-K7satSGvJqZDO1QO9M6Q6Tl3HmndPRIRrkNdzq4_ZJbTiq68dzN535TH75Ks0junwPQ$>

    -- https://urldefense.com/v3/__https://mail.python.org/mailman/listinfo/python-list__;!!Cn_UX_p3!g11w53LvI3sz4DsypU-K7satSGvJqZDO1QO9M6Q6Tl3HmndPRIRrkNdzq4_ZJbTiq68dzN535TH75Ks0junwPQ$<https://urldefense.com/v3/__https:/mail.python.org/mailman/listinfo/
    python-list__;!!Cn_UX_p3!g11w53LvI3sz4DsypU-K7satSGvJqZDO1QO9M6Q6Tl3HmndPRIRrkNdzq4_ZJbTiq68dzN535TH75Ks0junwPQ$>

    -- https://urldefense.com/v3/__https://mail.python.org/mailman/listinfo/python-list__;!!Cn_UX_p3!g11w53LvI3sz4DsypU-K7satSGvJqZDO1QO9M6Q6Tl3HmndPRIRrkNdzq4_ZJbTiq68dzN535TH75Ks0junwPQ$<https://urldefense.com/v3/__https:/mail.python.org/mailman/listinfo/
    python-list__;!!Cn_UX_p3!g11w53LvI3sz4DsypU-K7satSGvJqZDO1QO9M6Q6Tl3HmndPRIRrkNdzq4_ZJbTiq68dzN535TH75Ks0junwPQ$>

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Thomas Passin@21:1/5 to Thomas Passin on Thu Dec 15 17:35:26 2022
    Oops,

    "items = dstr[1:-2].split(',')"

    should have read

    "items = dstr[1:-1].split(',')".

    On 12/15/2022 1:56 PM, Thomas Passin wrote:
    It's hard to be sure from what you have offered, but I suspect that you
    are taking the string "(2022, 12, 13,  5,  3, 30)" from the file and
    using it as is.  When you feed that in as a starred argument, the string gets treated as a sequence where each item is a character in the string.
     Your example contains 26 characters, which matches the error message,
    so that's probably what is going on.

    You need to convert the string into the correct integers, because is the datetime function expects to get integers, not strings.  It isn't going
    to work with a string that looks like a tuple when it is printed.

    Here is one way you could do this.  From the input file, extract the
    string. Call it dstr.  Then you have to get rid of the parentheses and separate out each item so you can convert it into an integer.  So:

    items = dstr[1:-2].split(',')  # This creates a list of strings.
    # print(items) --> ['2022', ' 12', ' 13', '  5', '  3', ' 3']

    # Create a tuple of integers from the string items
    seq = (int(n) for n in items)
    # or make it a list instead: seq = [int(n) for n in items]

    # And here is the datetime object you wanted
    d1 = datetime.datetime(*seq)


    On 12/15/2022 1:14 PM, Gronicus@SGA.Ninja wrote:
    So far so good , I can now use a variable in datetime.datetime but it
    only
    works if I hard-code the time/date information. Now I want to have the
    code
    read from a file but I get: TypeError: function takes at most 9 arguments
    (26 given)

    I figure that the structure in the file is incorrect. What should it
    be? The
    entry in the file is (2022, 12, 13,  5,  3, 30) but when my program
    tries to
    use it I get the error.

    The program is a bit more sophisticated now but here is the update with a
    sample of the SPECIFICATIONS.txt file:
    =====================================================================

    # This program compares two Timedate values, subtracts the two and
    # converts the difference to seconds and hours.
    #

    #  %A Monday    #  %a Mon           #  %B January   #  %b Jan
    #  %d 05 day    #  %m month as 01   #  %Y 2020      #  %y 20 >> #  %H 24        #  %I 12            #  %M 30 min    #  %S Seconds

    import time
    import datetime
    from time import gmtime, strftime ##define strftime as time/date right
    now
    # ======================================================

    def GetSpecByItem(GetThisOne):  #get line by item in column 4 - 7
         ItemValue = "--"
         with open("SPECIFICATIONS.txt" , 'r') as infile:
          for lineEQN in infile: # loop to find each line in the file for >> that
    dose
             if ((lineEQN[4:7]== GetThisOne)):
                ItemValue = lineEQN[30:60].strip()   # Just the Data
         return(ItemValue)

    """
    SPECIFICATIONS.txt

    IYf HRB Humalog R Date           (2018, 12, 4, 10,  7, 00)           ##
    IYf HRG Humulin R Date           (2022, 12, 13,  5,  3, 30)          ##
    """
    # ====================== Main() ======================================
    print()
    Startt = "404"
    Stopp  = "404"

    Answer = "Y"
    Answer = input("Run test A? (" + Answer + ")" )

    if Answer == "Y" or Answer == "y" or Answer == "":
        print()
        print("     Running Test A:")
    #           Year  Mth Day Hour Min Sec
        Startt  =   2018, 12, 4, 10,  7, 00
        Stopp   =   2022, 12, 12, 1, 15, 30
        NowTime =   2022, 12, 14, 21, 15, 30
    else:
        print("     Running Test B:")
        Startt = GetSpecByItem("HRG")
        Stopp =  GetSpecByItem("HRB")
        NowTime = strftime("(%Y, %m, %d, %H, %M, %S)")
    print()
    print("55    NowTime = " + str(NowTime))
    print("56     Startt = " + str(Startt))
    print("57      Stopp = " + str(Stopp))
    print()

    NowTime =  datetime.datetime(*NowTime)
    Startt =   datetime.datetime(*Startt)
    Stopp =    datetime.datetime(*Stopp)

    #Start == Startt  # True"
    #print("Startt test = " + Start)
    # =================================================
    print()
    c = NowTime - Stopp
    minutes = c.total_seconds() / 60
    minutes = c.seconds / 60
    hours = 0

    while (minutes > 59):
             minutes = minutes - 60
             hours += 1
    minutes = round(minutes)
    print ("77 Hours =     <" + str(hours) + ">")
    print ("78 Minutes =   <" + str(minutes) + ">")
    if hours > 7:
         print(" Time to inject Humulin R u500.")

    pause = input("Pause")
    # ======================================================


    -----Original Message-----
    From: Python-list <python-list-bounces+gronicus=sga.ninja@python.org> On
    Behalf Of Thomas Passin
    Sent: Tuesday, December 13, 2022 11:20 PM
    To: python-list@python.org
    Subject: Re: Subtracting dates to get hours and minutes

    Your problem is that datetime.datetime does not accept a tuple as an
    argument.  It expects an integer value for the first argument, but you
    supplied a tuple.  In Python, you can use a sequence (e.g., tuple or
    list) the way you want by prefixing it with an asterisk.  This causes the >> sequence of items to be treated as individual arguments. So:

    Startt = datetime.datetime(2022, 12, 13,  5,  3, 30)
    st1 = (2022, 12, 13,  5,  3, 30)
    dts1 = datetime.datetime(*st1)  # NOT datetime.datetime(st1)
    dts1 == Startt  # True

    On 12/13/2022 10:43 PM, Gronicus@SGA.Ninja wrote:
       As is, Test A works.
       Comment out Test A and uncomment Test B it fails.
       In Test B, I move the data into a variable resulting with the report: >>>               "TypeError: an integer is required (got type tuple)

    How do I fix this?

    #---------------------------------------------------------------------
    --------
    import datetime
    #=================================================
    #         Test A   Hard coded Date/Time
    Startt = datetime.datetime(2022, 12, 13,  5,  3, 30) Stopp =
    datetime.datetime(2022, 12, 12, 21, 15, 30)

    # =================================================
    #         Test B   Date/Time data as a variable
    #Startt = (2022, 12, 13,  5,  3, 30)
    #Stopp =  (2022, 12, 12, 21, 15, 30)

    #Startt = datetime.datetime(Startt)
    #Stopp =  datetime.datetime(Stopp)

    # =================================================
    c = Startt - Stopp
    minutes = c.total_seconds() / 60
    minutes = c.seconds / 60
    hours = 0

    while (minutes > 59):
              minutes = minutes - 60
              hours += 1
    minutes = round(minutes)
    print()
    print ("       Hours =  <" + str(hours) + ">")
    print ("     Minutes =  <" + str(minutes) + ">")

    #
    ----------------------------------------------------------------------
    -------


    --
    https://mail.python.org/mailman/listinfo/python-list



    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From MRAB@21:1/5 to Gronicus@SGA.Ninja on Fri Dec 16 04:34:06 2022
    On 2022-12-15 22:49, Gronicus@SGA.Ninja wrote:
    Yes, it works like a charm. On the tupility of it all.
    Special thanks for the explanation too…..



    (Originally asked but I found the errors. All is working)

    Now that the code no longer produces the errors, I see that the year and month not included in the calculation? How do I fix this?


    How long is a month? How many months are there until January 1? On
    December 25, many months will there be until January 1? And how many
    years are there until January 1?

    [snip]

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Thomas Passin@21:1/5 to MRAB on Fri Dec 16 00:25:22 2022
    On 12/15/2022 11:34 PM, MRAB wrote:
    On 2022-12-15 22:49, Gronicus@SGA.Ninja wrote:
    Yes, it works like a charm. On the tupility of it all.
    Special thanks for the explanation too…..


    (Originally asked but I found the errors. All is working)

    Now that the code no longer produces the errors, I see that the year
    and month not included in the calculation? How do I fix this?

    First you should read about the function you are using. In this case,
    it is at

    https://docs.python.org/3.10/library/datetime.html

    I found this page using an internet search for "python datetime.datetime".

    All Python functions, classes, and methods will normally be found in the documentation for the standard library, as this one is.

    You should also look at datetime.timedelta, as various people have
    posted here. Try to understand what is being described. Then try to
    make simple examples that will show if you can get what you want, or if
    not, what more information you need. Look through the rest of the documentation of (in this case) the datetime module and see if any of
    the other functionality looks like it will produce what you want.

    It is important to understand clearly what your input data is like, and
    what results you need to achieve. If you are not clear, or do not
    express yourself clearly, it will be hard and frustrating for others on
    the list to assist you.

    For example, you wrote "I see that the year and month not included in
    the calculation". I don't know what you mean. You already include the
    month in the tuple that you feed to datetime.datetime(). That is, in
    the input string you showed, "(2022, 12, 13, 5, 3, 30)", it seems that
    "2022" represents a year, "12" represents a month, "13" represents a day
    of the month, and so forth.

    So I don't understand how year and month not included. I see that you
    do think that something is not coming out right, but you need to be more precise about what you mean so that others can understand too.

    To succeed at programming, you need to be very precise about attending
    to details because the computer cannot know what you have in your mind.
    To succeed at getting help, you have to be precise and accurate about
    what you want to achieve and what is not coming out right, and describe
    those things simply and clearly to other people.

    In other words, please help us to help you.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)