Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #69946
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.albasani.net!news.stack.nl!newsfeed.xs4all.nl!newsfeed4a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <python.list@tim.thechases.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.035 |
| X-Spam-Evidence | '*H*': 0.93; '*S*': 0.00; 'cc:addr:python-list': 0.11; 'def': 0.12; '-tkc': 0.16; 'address):': 0.16; 'from:addr:python.list': 0.16; 'from:addr:tim.thechases.com': 0.16; 'from:name:tim chase': 0.16; 'pressed': 0.16; '\xc2\xa0if': 0.16; 'wrote:': 0.18; 'cc:addr:python.org': 0.22; 'print': 0.22; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; 'header:In-Reply- To:1': 0.27; 'class': 0.32; 'skip:b 30': 0.33; 'skip:_ 10': 0.34; 'could': 0.34; 'something': 0.35; 'button': 0.38; '8bit%:4': 0.38; 'ends': 0.38; 'subject:" ': 0.39; 'entire': 0.61; 'address': 0.63; 'become': 0.64; 'received:50.22': 0.84; 'self.value': 0.84 |
| Date | Wed, 9 Apr 2014 08:34:26 -0500 |
| From | Tim Chase <python.list@tim.thechases.com> |
| To | Grawburg <grawburg@myglnc.com> |
| Subject | Re: "Latching" variables in function |
| In-Reply-To | <7ffe44a68f47a64f5120d3a6c6a660b5@myglnc.com> |
| References | <7ffe44a68f47a64f5120d3a6c6a660b5@myglnc.com> |
| X-Mailer | Claws Mail 3.8.1 (GTK+ 2.24.10; x86_64-pc-linux-gnu) |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=UTF-8 |
| Content-Transfer-Encoding | quoted-printable |
| X-AntiAbuse | This header was added to track abuse, please include it with any abuse report |
| X-AntiAbuse | Primary Hostname - boston.accountservergroup.com |
| X-AntiAbuse | Original Domain - python.org |
| X-AntiAbuse | Originator/Caller UID/GID - [47 12] / [47 12] |
| X-AntiAbuse | Sender Address Domain - tim.thechases.com |
| X-Get-Message-Sender-Via | boston.accountservergroup.com: authenticated_id: tim@thechases.com |
| Cc | python-list@python.org |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.9072.1397050472.18130.python-list@python.org> (permalink) |
| Lines | 40 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1397050472 news.xs4all.nl 2879 [2001:888:2000:d::a6]:40581 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:69946 |
Show key headers only | View raw
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 comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: "Latching" variables in function Tim Chase <python.list@tim.thechases.com> - 2014-04-09 08:34 -0500
csiph-web