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


Groups > comp.lang.python > #76490

Re: Set static attributes...maybe.

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <ckaynor@zindagigames.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.003
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'static': 0.04; 'class,': 0.07; 'everybody,': 0.07; 'attributes': 0.09; 'convention,': 0.09; 'required,': 0.09; 'subject:skip:a 10': 0.09; 'cc:addr:python- list': 0.11; 'def': 0.12; 'creates': 0.14; '(),': 0.16; '10:00': 0.16; '@classmethod': 0.16; 'personally,': 0.16; 'skip:{ 30': 0.16; 'wrote:': 0.18; 'example': 0.22; 'aug': 0.22; 'email addr:gmail.com&gt;': 0.22; 'cc:addr:python.org': 0.22; 'mon,': 0.24; 'cc:2**0': 0.24; 'pass': 0.26; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'am,': 0.29; 'skip:@ 10': 0.30; 'message- id:@mail.gmail.com': 0.30; 'skip:( 20': 0.30; "i'm": 0.30; 'class': 0.32; 'probably': 0.32; 'skip:_ 10': 0.34; 'received:74.125.82': 0.34; 'could': 0.34; 'connection': 0.35; 'skip:s 30': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'instances': 0.36; 'method': 0.36; 'similar': 0.36; 'two': 0.37; 'skip:& 10': 0.38; 'that,': 0.38; 'skip:& 20': 0.39; 'received:74.125': 0.39; 'does': 0.39; 'name': 0.63; 'to:addr:gmail.com': 0.65; 'p.s.': 0.66; 'receive': 0.70; 'special': 0.74; 'clearer': 0.84; 'subject:Set': 0.91
X-Google-DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-type; bh=+RquWmbz5gy7f/syQxTdbHDuMiZ77Gn8YuvzXIpL9yA=; b=YnvzLQ+TAzUE3y742N7/3Am8zr84gtan1s8YLScBb4Poc5kl1+ZubbgKTVWRjxa6Ac mzP0PM6bE0IRxXAT4lrqpkZ2ysQvzv0HNffTtlbL+8ShoFc19Bnnp/ndmE5VNI9TxmJL BZFcuU1F/pkPMUY3pw5YQaTNAH+Trz4Z1m5s/t/6G4jNBeJZu4YlELGRtY5AHOqWnJHj EBqkYn269Qn3xT7OYHGECsEtiyrZpifCYYB6Xs0oCRovMgEFh1Hd16uWDgxRa/UzHR5u n/Fxc4otGki9MKt2PzNGjl2dg4d6csASkEFnSNSNCT8Xq+FsgaRWqz0WBH1P+gA0NPyX KDBg==
X-Gm-Message-State ALoCoQmzWZGfJDRjCZkWMj+GI3A4pWLQIt+iyyo9IdXTyOZmPSBmWSrump0SLOLe2noy/8wPHEpt
X-Received by 10.180.91.70 with SMTP id cc6mr335271wib.66.1408382008154; Mon, 18 Aug 2014 10:13:28 -0700 (PDT)
MIME-Version 1.0
In-Reply-To <5cb1f29f-b502-4509-be42-1d053f89fbbd@googlegroups.com>
References <5cb1f29f-b502-4509-be42-1d053f89fbbd@googlegroups.com>
From Chris Kaynor <ckaynor@zindagigames.com>
Date Mon, 18 Aug 2014 10:13:08 -0700
Subject Re: Set static attributes...maybe.
To Beppe <giuseppecostanzi@gmail.com>
Content-Type multipart/alternative; boundary=f46d0438edd74df0da0500ea7d87
Cc "python-list@python.org" <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.13103.1408382015.18130.python-list@python.org> (permalink)
Lines 128
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1408382015 news.xs4all.nl 2883 [2001:888:2000:d::a6]:38673
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:76490

Show key headers only | View raw


[Multipart message — attachments visible in raw view] - view raw

On Mon, Aug 18, 2014 at 10:00 AM, Beppe <giuseppecostanzi@gmail.com> wrote:

> hi to everybody,
> in the following scrip I try to call the function read_parameters () but
> returns me that wants two arguments!?!?!
> My intent is to have in the class, Engine (), some static attributes that
> can be used by  other instances without to redefine this every time.
> These matters could be for example a path or a connection to a database.
> suggestions?
>
> regards
> beppe
>
> class Master(object):
>     def __init__(self,):
>         pass
>
> class Engine(Master):
>     dict_parameters = {}
>     def __init__(self,):
>         super(Engine, self).__init__()
>
>     @staticmethod
>     def read_parameters(self,path):
>
>         self.dict_parameters = {1:"a",2:"b"}
>

What you probably want here, based on your description is (untested):
@classmethod
def read_parameters(cls, path): # Note, the name is "cls". This is not
required, but is convention, similar to "self".
    cls.dict_parameters = {1:"a",2:"b"}

@staticmethod creates a method that does not receive any special parameter,
so the signature would be "def read_parameters(path)".

Note that, personally, I would name the method "parse_parameters" to make
it clearer what it does.


>
>     def check_parameters(self):
>         self.read_parameters("hello_world")


>
> foo=Engine()
> foo.check_parameters()
>
> p.s.
> I'm on Debian 6
>

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


Thread

Set static attributes...maybe. Beppe <giuseppecostanzi@gmail.com> - 2014-08-18 10:00 -0700
  Re: Set static attributes...maybe. Chris Kaynor <ckaynor@zindagigames.com> - 2014-08-18 10:13 -0700
    Re: Set static attributes...maybe. Beppe <giuseppecostanzi@gmail.com> - 2014-08-18 10:33 -0700

csiph-web