Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.051 X-Spam-Evidence: '*H*': 0.90; '*S*': 0.00; 'true,': 0.05; 'variable,': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; 'def': 0.12; 'jan': 0.12; 'assume': 0.14; "'port": 0.16; 'handler.': 0.16; 'pressed': 0.16; 'received:mac.com': 0.16; 'reedy': 0.16; 'runs,': 0.16; 'wrote:': 0.18; 'do.': 0.18; 'variable': 0.18; 'possible,': 0.19; 'received:10.0.1': 0.19; 'skip:p 40': 0.19; 'cc:addr:python.org': 0.22; 'cc:2**1': 0.23; 'skip': 0.24; 'cc:no real name:2**0': 0.24; "i've": 0.25; 'asking': 0.27; 'gets': 0.27; 'function': 0.29; 'am,': 0.29; "i'm": 0.30; 'program,': 0.31; 'code': 0.31; 'probably': 0.32; 'call.': 0.33; 'could': 0.34; "can't": 0.35; 'test': 0.35; 'but': 0.35; 'there': 0.35; 'really': 0.36; 'next': 0.36; 'method': 0.36; 'received:10.0': 0.36; 'wrong': 0.37; 'project': 0.37; 'received:10': 0.37; 'button': 0.38; 'arrange': 0.38; 'depends': 0.38; 'ends': 0.38; 'received:17': 0.38; 'pm,': 0.38; 'little': 0.38; 'subject:" ': 0.39; 'called': 0.40; 'how': 0.40; 'entire': 0.61; 'back': 0.62; 'term': 0.63; 'become': 0.64; 'charset:windows-1252': 0.65; 'periodically': 0.68; 'square': 0.74; 'plc': 0.78; 'truth': 0.81; '2014,': 0.84; 'books.': 0.84; 'header:In-reply-to:1': 0.84; 'interrupt': 0.84; 'isn\x92t': 0.84; 'it\x92s': 0.84; 'can\x92t': 0.91 MIME-version: 1.0 Content-type: text/plain; charset=windows-1252 Subject: Re: "Latching" variables in function From: William Ray Wing In-reply-to: Date: Wed, 09 Apr 2014 08:12:32 -0400 Content-transfer-encoding: quoted-printable References: <7ffe44a68f47a64f5120d3a6c6a660b5@myglnc.com> To: Terry Reedy X-Mailer: Apple Mail (2.1874) X-MANTSH: 1TEIXREEbG1oaGkdHB0lGUkdDRl5PWBoaHxEKTEMXGx0EGx8SBBscHwQdGxAbHho fGhEKWE0XSxEKbX4XGhEKTFkXGxobGxEKWUkXEQpZXhdjbnkRCkNOF0sbGxpiTk0caBlsbBl4c wcZExsYGxhLGxEKWFwXGQQaBB0HTUsdEkhJHEwFGx0EGx8SBBscHwQdGxAbHhofGxEKXlkXYU9 eGXoRCkxGF2xraxEKQ1oXHxoEGx4dBBweBBgbEQpEWBcZEQpESRcYEQpCRRdrRAV6XlNNZUZ5e BEKQk4XaEZCQB9IeR1HH2QRCkJMF2J6ehpvUBNnUFlZEQpCbBdkZGZzblhHSGV9RhEKQkAXaH9 ifgFdSE5QZkYRCnBoF2l9Z2l/THhPGnlJEQpwaBdrbEFdaEZ+aFlDRBEKcGgXaBIFG1lpQkJIY 0kRCnBoF2JyTGNOXhxGbm1/EQpwaBdiYFhfS1ATAXpHYxEKcGwXbm4STxxjeGBnUmURCnBMF2l lQmt8Yn9PSH5uEQ== X-CLX-Spam: false X-CLX-Score: 1011 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:5.11.96,1.0.14,0.0.0000 definitions=2014-04-09_01:2014-04-09,2014-04-09,1970-01-01 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 suspectscore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=7.0.1-1402240000 definitions=main-1404090055 Cc: python-list@python.org, "William R. Wing" X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 47 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1397049182 news.xs4all.nl 2940 [2001:888:2000:d::a6]:33138 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:69944 On Apr 9, 2014, at 12:35 AM, Terry Reedy wrote: > On 4/8/2014 4:09 PM, Grawburg wrote: >>=20 >> I've probably used the wrong term - I'm thinking of what I do when = writing PLC code - so I can't find how to do this in my reference books. >> This is part of a project I'm working on with a Raspberry Pi and an = MCP23017 port expander. >> I have a N/O pushbutton that I want to "latch" a value to a variable = when it's been pressed. I have this function that gets called = periodically in >> a 'while True' statement: >>=20 >> def button(): >> pushbutton =3D 0 >> button_value =3D 0 >> pushbutton=3Dbus.read_byte_data(address,GPIOB) >> if pushbutton > 0: >> button_value =3D 1 >> return button_value >>=20 >> 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() >>=20 >> What do I use to 'latch' button_value? >=20 > It depends on whether you can set up your system so that pushing the = button generates an interrupt. But I know little about R.Pi and less = about the 'port expander'. If there were an interrupt, you would just = have to write an interrupt handler. When possible, this is much better = than polling. >=20 > --=20 > Terry Jan Reedy >=20 I think what the OP was asking for was a way in standard Python to = =93lock" the value of an instance variable, which of course, you really = can=92t do. However, what he (I assume it=92s a he) could do is arrange = his calling program so that after the button method returns a =931=94, = the method isn=92t called again. That is, test for truth of button =3D = 1 in the calling program, and if true, skip the call. The next time the = program runs, the button value will be re-initialized to zero and = everything is back to square one. -Bill=