Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Global - local variables
#11
You do not return anything from nuseryControlFunction if nuserySWdatabase == 0 and nersFlag. Functions that return values need to always return a values.
Reply
#12
Smile 
Yes forgot the return had nothing if not going through IF statements. Change to below code which at present seems to be working ok. Probable not best way to get this done but seems to be working :).

Thanks for the link, this is really useful

import datetime

nersFlag = False
nuserySWdatabase = 0
nersOffTime = 0

def nuseryControlFunction(nuserySWdatabase, nersFlag, nersOffTime):
    if nuserySWdatabase == 0 and not nersFlag:
        print ("pump on")
      #  GPIO.output(pump, GPIO.LOW)
        nersOffTime = datetime.datetime.now() + datetime.timedelta(seconds=30)
        print (nersOffTime)
        print (now)
        nersFlag = True
    if nuserySWdatabase == 1:
        print ("pump off")
      #  GPIO.output(pump, GPIO.HIGH)
        nersOffTime = 0
        nersFlag = False
    if nersOffTime < now:
        print "shutdown"
    return nersFlag, nersOffTime

while True:
    now = datetime.datetime.now()
    nersFlag, nersOffTime = nuseryControlFunction(nuserySWdatabase, nersFlag, nersOffTime)

    
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  It's saying my global variable is a local variable Radical 5 1,155 Oct-02-2023, 12:57 AM
Last Post: deanhystad
  Trying to understand global variables 357mag 5 1,115 May-12-2023, 04:16 PM
Last Post: deanhystad
  Delete all Excel named ranges (local and global scope) pfdjhfuys 2 1,774 Mar-24-2023, 01:32 PM
Last Post: pfdjhfuys
  Global variables or local accessible caslor 4 1,021 Jan-27-2023, 05:32 PM
Last Post: caslor
  global variables HeinKurz 3 1,143 Jan-17-2023, 06:58 PM
Last Post: HeinKurz
  How to use global value or local value sabuzaki 4 1,151 Jan-11-2023, 11:59 AM
Last Post: Gribouillis
  Clarity on global variables JonWayn 2 943 Nov-26-2022, 12:10 PM
Last Post: JonWayn
  Global variables not working hobbyist 9 4,719 Jan-16-2021, 03:17 PM
Last Post: jefsummers
  Global vs. Local Variables Davy_Jones_XIV 4 2,650 Jan-06-2021, 10:22 PM
Last Post: Davy_Jones_XIV
  from global space to local space Skaperen 4 2,312 Sep-08-2020, 04:59 PM
Last Post: Skaperen

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020