Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #42279

Re: Python class and variable issue(newby question!)

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!us.feeder.erje.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.022
X-Spam-Evidence '*H*': 0.96; '*S*': 0.00; 'example:': 0.03; 'static': 0.04; 'subject:Python': 0.06; 'global,': 0.09; 'subject:question': 0.10; 'def': 0.12; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'subject:class': 0.16; 'subject:issue': 0.16; 'subject:variable': 0.16; 'variable.': 0.16; 'sat,': 0.16; 'wrote:': 0.18; 'helpful': 0.24; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; 'message-id:@mail.gmail.com': 0.30; 'code': 0.31; 'class': 0.32; 'actual': 0.34; 'received:209.85': 0.35; 'received:209.85.220': 0.35; 'beyond': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'url:org': 0.36; 'received:209': 0.37; 'to:addr:python-list': 0.38; 'that,': 0.38; 'help,': 0.39; 'to:addr:python.org': 0.39; 'either': 0.39; 'most': 0.60; 'simple': 0.61; 'more': 0.64; '30,': 0.65; 'mar': 0.68; 'sam': 0.68; 'berry': 0.84; "it'd": 0.84; 'subject:!)': 0.84; '2013': 0.98
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:content-type; bh=srgN0a8Zy+81iN9zSncl6V7HUe2f1KfMmdSCkPN67MU=; b=NrSVrC+rKnt4PzYDxRCMMK6eb2dy11M8eyXP/2y+uvbWhdlrLMmVpPU9y8hFR+JcKB uxbAJEFveR2+o5lcoc6cKFhB4IfS2FyuZ9AVwaU0Iy+WbJp6mG4uShx1jnLIApYo1w55 xg5ogQW/GgWCp9PKUMcOpg/anMSd57OuBiFeKKfEW/cGulXbrtphUjNG9vj6t2N5nzCr M2V/jWLJquXkvfid5/ojGo/Pyq/MIthflKXTdW4D+Jfhw3va7nP/JIn/TrqsAwyQ2TB3 atndcU5qjYnEXydMBOp9EYzbJY0mHtX3+37UUWP200/S3u/O+8w/vm1r9S52wHwfIAC8 AGmg==
MIME-Version 1.0
X-Received by 10.220.109.145 with SMTP id j17mr2938172vcp.34.1364592240987; Fri, 29 Mar 2013 14:24:00 -0700 (PDT)
In-Reply-To <78680654-5cf5-435c-9fce-19d6f5c23360@googlegroups.com>
References <78680654-5cf5-435c-9fce-19d6f5c23360@googlegroups.com>
Date Sat, 30 Mar 2013 08:24:00 +1100
Subject Re: Python class and variable issue(newby question!)
From Chris Angelico <rosuav@gmail.com>
To python-list@python.org
Content-Type text/plain; charset=ISO-8859-1
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.3965.1364592243.2939.python-list@python.org> (permalink)
Lines 26
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1364592243 news.xs4all.nl 6875 [2001:888:2000:d::a6]:56933
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:42279

Show key headers only | View raw


On Sat, Mar 30, 2013 at 8:12 AM, Sam Berry <sambez_14@hotmail.co.uk> wrote:
> class test()
>     s = 1
>
>     def test1()
>         global s
>         s = 2
>
>     def test2()
>         global s
>         s = 3
>
>     def test3()
>         global s
>         s = 4

That's not a global, that's a class variable. But to give any more
specific help, it'd be helpful to have some actual working code -
twiddle your code until it's a nice simple example:

http://sscce.org/

Most likely, what you want is to make these functions into either
static methods or instance methods. Beyond that, hard to say exactly.

ChrisA

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


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