Python Forum
How to use an Emulator and a MttQ broker?
Thread Rating:
  • 1 Vote(s) - 1 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to use an Emulator and a MttQ broker?
#9
EntOn() does not have a return, so by default it returns None. None does not equal True or False. None is false-ey, so it acts like False when used in an if statement, but it is not False (because they are different objects) and it does not equal False (because they are different types (None is class NoneType, False is class bool).

EntOn = False assigns EntOn to reference the object False. Now EntOn is False and cannot be used to call the function EntOn(). It is like you deleted the function from the program. It can no longer be used.
def EntOn():
    pass

print("EntOn", EntOn, type(EntOn), id(EntOn))
print("EntOn()", EntOn(), type(EntOn()), id(EntOn()))

EntOn = False
print("EntOn = False", EntOn, False, id(EntOn), id(False))

print("Call EntOn")
EntOn()
Output:
EntOn <function EntOn at 0x000001C713F108B0> <class 'function'> 1954544683184 EntOn() None <class 'NoneType'> 140735532587136 EntOn = False False False 140735532537712 140735532537712 Call EntOn Traceback (most recent call last): File "c:/Users/djhys/Documents/python/musings/junk.py", line 11, in <module> EntOn() TypeError: 'bool' object is not callable
From the program output you can see that EntOn starts out as a function and calling the function returns None. After assigning EntOn = False, EntOn is now the object False (They have the same object ID which means they are the same object). Now that EntOn is the same as False, calling EntOn() is the same as calling False().
Reply


Messages In This Thread
RE: How to use an Emulator and a MttQ broker? - by deanhystad - Jul-03-2022, 04:46 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  pyautogui with a display emulator? gumby4231 0 2,673 Jul-30-2020, 02:46 PM
Last Post: gumby4231
  running python script from shell invoked with os.system("x-terminal-emulator -e /bin/ markhaus 2 3,181 Feb-21-2019, 11:55 PM
Last Post: markhaus

Forum Jump:

User Panel Messages

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