Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #69946 > unrolled thread
| Started by | Tim Chase <python.list@tim.thechases.com> |
|---|---|
| First post | 2014-04-09 08:34 -0500 |
| Last post | 2014-04-09 08:34 -0500 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: "Latching" variables in function Tim Chase <python.list@tim.thechases.com> - 2014-04-09 08:34 -0500
| From | Tim Chase <python.list@tim.thechases.com> |
|---|---|
| Date | 2014-04-09 08:34 -0500 |
| Subject | Re: "Latching" variables in function |
| Message-ID | <mailman.9072.1397050472.18130.python-list@python.org> |
On 2014-04-08 16:09, Grawburg wrote:
> def button():
> pushbutton = 0
> button_value = 0
> pushbutton=bus.read_byte_data(address,GPIOB)
> if pushbutton > 0:
> button_value = 1
> return button_value
>
> I need button_value to become '1' when the button is pressed and to
> remain '1' until the entire program (only about 25 lines) ends with
> a sys.exit()
>
> What do I use to 'latch' button_value?
If I understand what you want, you could do something like
class LatchButton:
def __init__(self, address):
self.value = 0
self.address = address
def __call__(self):
if not self.value:
if bus.read_byte_data(self.address, GPIOB) > 0:
self.value = 1
return self.value
button1 = LatchButton(address1)
button2 = LatchButton(address2)
for i in range(10):
print button1(), button2()
time.sleep(3)
-tkc
Back to top | Article view | comp.lang.python
csiph-web