Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed1.swip.net!uio.no!news.tele.dk!news.tele.dk!small.news.tele.dk!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: UNSURE 0.321 X-Spam-Level: *** X-Spam-Evidence: '*H*': 0.37; '*S*': 0.01; 'def': 0.12; 'pressed': 0.16; '\xc2\xa0i': 0.16; '\xc2\xa0if': 0.16; 'variable': 0.18; "i've": 0.25; 'gets': 0.27; 'function': 0.29; "i'm": 0.30; 'code': 0.31; 'probably': 0.32; 'brian': 0.33; 'received:66': 0.35; "can't": 0.35; 'wrong': 0.37; 'project': 0.37; 'button': 0.38; '8bit%:4': 0.38; 'ends': 0.38; 'to:addr:python-list': 0.38; 'subject:" ': 0.39; 'to:addr:python.org': 0.39; 'called': 0.40; 'how': 0.40; 'subject:"': 0.60; 'free': 0.61; 'entire': 0.61; 'first': 0.61; 'you.': 0.62; 'term': 0.63; 'become': 0.64; 'north': 0.65; 'periodically': 0.68; 'plc': 0.78; 'truth': 0.81; 'books.': 0.84; 'received:192.168.55': 0.84 X-ASG-Debug-ID: 1396987765-067885457a18cbb0001-tYLEC7 X-Barracuda-Envelope-From: grawburg@myglnc.com Date: Tue, 08 Apr 2014 16:09:28 -0400 X-Barracuda-Apparent-Source-IP: 216.152.2.119 To: python-list@python.org From: Grawburg Subject: "Latching" variables in function X-ASG-Orig-Subj: "Latching" variables in function X-Mailer: IceWarp Mailer 10.3.1 X-Priority: 3 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 X-Barracuda-Connect: UNKNOWN[192.168.55.60] X-Barracuda-Start-Time: 1396987765 X-Barracuda-URL: http://192.168.55.85:8000/cgi-mod/mark.cgi X-Barracuda-Spam-Score: 0.00 X-Barracuda-Spam-Status: No, SCORE=0.00 using global scores of TAG_LEVEL=1000.0 QUARANTINE_LEVEL=1000.0 KILL_LEVEL=4.4 tests= X-Barracuda-Spam-Report: Code version 3.2, rules version 3.2.3.4697 Rule breakdown below pts rule name description ---- ---------------------- -------------------------------------------------- X-Mailman-Approved-At: Wed, 09 Apr 2014 01:48:40 +0200 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: 40 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1397000922 news.xs4all.nl 2941 [2001:888:2000:d::a6]:39336 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:69908 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. =C2=A0I have this function that gets called = periodically in a 'while True' statement: def button(): =C2=A0 =C2=A0pushbutton =3D 0 =C2=A0 button_value =3D 0 =C2=A0 =C2=A0pushbutton=3Dbus.read_byte_data(address,GPIOB) =C2=A0 =C2=A0if pushbutton > 0: =C2=A0 =C2=A0 =C2=A0 =C2=A0 button_value =3D 1 =C2=A0 =C2=A0return 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? Brian Grawburg North Carolina --=20 The truth will set you free . . .but first it will infuriate you.