Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #42282
| Path | csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <bsk16@case.edu> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.009 |
| X-Spam-Evidence | '*H*': 0.98; '*S*': 0.00; 'subject:Python': 0.06; 'attribute': 0.07; 'class,': 0.07; 'assigning': 0.09; 'buttons': 0.09; 'classes.': 0.09; 'creator': 0.09; 'global,': 0.09; 'runs': 0.10; 'subject:question': 0.10; 'def': 0.12; 'gui': 0.12; 'class).': 0.16; 'guessing': 0.16; 'insights': 0.16; 'local.': 0.16; 'subject:class': 0.16; 'subject:issue': 0.16; 'subject:variable': 0.16; 'variable.': 0.16; 'thanks,': 0.17; 'wrote:': 0.18; 'variable': 0.18; 'trying': 0.19; 'example': 0.22; 'programming': 0.22; 'print': 0.22; 'exists': 0.24; 'module,': 0.24; 'sends': 0.24; 'test.': 0.24; 'class.': 0.26; 'header:In- Reply-To:1': 0.27; 'message-id:@mail.gmail.com': 0.30; 'code': 0.31; 'posting': 0.31; 'changed.': 0.31; 'prints': 0.31; 'allows': 0.31; 'class': 0.32; 'figure': 0.32; 'run': 0.32; 'another': 0.32; 'fri,': 0.33; 'actual': 0.34; 'received:209.85': 0.35; 'test': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'instances': 0.36; 'received:209': 0.37; 'button': 0.38; 'to:addr :python-list': 0.38; 'issue': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; 'changed': 0.39; 'either': 0.39; 'called': 0.40; 'how': 0.40; 'even': 0.60; 'solve': 0.60; 'new': 0.61; 'simple': 0.61; "you're": 0.61; 'here:': 0.62; "you'll": 0.62; 'different': 0.65; 'within': 0.65; 'here': 0.66; 'mar': 0.68; 'sam': 0.68; 'hey,': 0.75; 'berry': 0.84; 'received:209.85.214.198': 0.84; 'received:mail- ob0-f198.google.com': 0.84; 'subject:!)': 0.84; 'working,': 0.84; '2013': 0.98 |
| X-Google-DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:mime-version:x-received:in-reply-to:references:date :message-id:subject:from:to:content-type:x-gm-message-state; bh=sJ3fAAB2/Ll9fqNkxRX960VGip58VonT+m5BS3GTxKo=; b=R/QLVwNM/iomGuCDSwzli2MPWa0YimvX7p9veClbZNFIIjvKbnoe+pVV7ZGlA64mqs 3O43gNJS3NQMrMDkisj4l3rveqhQMVuu4r6yNMaLfnu2DtTIFDCx85rMr4YKOkEfmmQ5 CTiEah1KGD2+nTO+aztBzvZuuuIfL2AGrnINA39n/wcXl4nW3GCT7HXuZJO1P3VmTEFg MguRREpKSYWDVUl3bfW+87c5pklemo1mWOtiKKBy3ghjwD+OAN5ZllU6oyZn0Sjq1bGf hVt5ZM1S6noKmj/4or9XASZus9PecoB61eRZTtZltYSwxfJ/BQeZHJ7sex3i0CgUnbqM icyw== |
| X-Received | by 10.60.169.237 with SMTP id ah13mr1305327oec.41.1364592193344; Fri, 29 Mar 2013 14:23:13 -0700 (PDT) |
| MIME-Version | 1.0 |
| X-Received | by 10.60.169.237 with SMTP id ah13mr1305325oec.41.1364592193263; Fri, 29 Mar 2013 14:23:13 -0700 (PDT) |
| In-Reply-To | <78680654-5cf5-435c-9fce-19d6f5c23360@googlegroups.com> |
| References | <78680654-5cf5-435c-9fce-19d6f5c23360@googlegroups.com> |
| Date | Fri, 29 Mar 2013 14:23:13 -0700 |
| Subject | Re: Python class and variable issue(newby question!) |
| From | Benjamin Kaplan <benjamin.kaplan@case.edu> |
| To | python-list@python.org |
| Content-Type | text/plain; charset=UTF-8 |
| X-Gm-Message-State | ALoCoQl5K6VBFzgWF7UdwItl30mZHgOZZL4jqVNOQLlfVkmzmDaFB311blKTj1tST2qW69AOx5WGkvgkkprjUg/yIfHU7ZDMqiki7O8xNedCbXv4Z+jxOHzFdAGdDX9wrWDvr9sDtFdULt72P1WswFRgrQvObZos6Q== |
| X-Junkmail-Whitelist | YES (by domain whitelist at mpv1.tis.cwru.edu) |
| 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 | <http://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 | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.3967.1364592579.2939.python-list@python.org> (permalink) |
| Lines | 43 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1364592579 news.xs4all.nl 6963 [2001:888:2000:d::a6]:35526 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:42282 |
Show key headers only | View raw
On Fri, Mar 29, 2013 at 2:12 PM, Sam Berry <sambez_14@hotmail.co.uk> wrote: > Hey, > > Im new to object orientated programming and have an issue with using classes. Im using the kivy module, a GUI creator , so posting the actual code may confuse. But an example of what im trying to achieve is below > > class test() > s = 1 > > def test1() > global s > s = 2 > > def test2() > global s > s = 3 > > def test3() > global s > s = 4 > > > class test4() > > def printing() > print test().s > > After been in the test()class a choice of buttons allows the user to run either of the functions within it and sends us into the test4() class. Then another button runs printing(). > > However printing() always prints 1, even if the variable has been changed. Im guessing because print test().s redefines the variable. May be a very simple to solve problem, but i cant figure it out. > > Any insights of how to get this working, or example code would be very helpful! > > Thanks, Sam > -- There are three different namespaces here: global, class, and local. You're assigning to the global s, which exists outside the class. Do "print s" instead of "print test().s" and you'll see your changed value of s. If you want to change the value of s inside the class, it's called "test.s" (notice that there's no parenthesis- that's because s here is an attribute of the test class, not each instance of test. The same value will be shared by all instances of that class).
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Python class and variable issue(newby question!) Sam Berry <sambez_14@hotmail.co.uk> - 2013-03-29 14:12 -0700
Re: Python class and variable issue(newby question!) Chris Angelico <rosuav@gmail.com> - 2013-03-30 08:24 +1100
Re: Python class and variable issue(newby question!) Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-03-29 22:51 +0000
Re: Python class and variable issue(newby question!) Chris Angelico <rosuav@gmail.com> - 2013-03-30 09:59 +1100
Re: Python class and variable issue(newby question!) Benjamin Kaplan <benjamin.kaplan@case.edu> - 2013-03-29 14:23 -0700
Re: Python class and variable issue(newby question!) Sam Berry <sambez_14@hotmail.co.uk> - 2013-03-29 15:17 -0700
Re: Python class and variable issue(newby question!) Chris Angelico <rosuav@gmail.com> - 2013-03-30 09:45 +1100
Re: Python class and variable issue(newby question!) Dave Angel <davea@davea.name> - 2013-03-29 18:56 -0400
csiph-web