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


Groups > comp.lang.python > #33960

Re: How to pass class instance to a method?

Return-Path <d@davea.name>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'python.': 0.02; 'argument': 0.04; 'run-time': 0.05; 'parameter': 0.07; 'statically': 0.07; 'subject:How': 0.09; 'python': 0.09; 'declarations': 0.09; 'subject:method': 0.09; 'typed': 0.09; 'typeerror:': 0.09; 'cc:addr:python-list': 0.10; 'def': 0.10; 'language,': 0.11; 'static': 0.13; 'foo(object):': 0.16; 'subject:class': 0.16; 'subject:instance': 0.16; 'subject:pass': 0.16; 'unbound': 0.16; 'mon,': 0.16; 'wrote:': 0.17; 'instance': 0.17; '"",': 0.22; 'defined': 0.22; 'cc:2**0': 0.23; 'example': 0.23; 'pass': 0.25; 'cc:addr:python.org': 0.25; 'header:In-Reply- To:1': 0.25; 'header:User-Agent:1': 0.26; '(most': 0.27; '>>>>': 0.29; 'arguments.': 0.29; 'checking.': 0.29; 'implied': 0.29; 'class': 0.29; 'function': 0.30; 'file': 0.32; 'function.': 0.33; 'int': 0.33; 'traceback': 0.33; 'languages': 0.33; 'nov': 0.35; 'pm,': 0.35; 'subject:?': 0.35; 'method': 0.36; 'uses': 0.37; 'previous': 0.37; 'subject:: ': 0.38; 'perform': 0.38; 'received:192': 0.39; 'called': 0.39; 'where': 0.40; 'received:192.168': 0.40; 'first': 0.61; '26,': 0.65; 'talking': 0.66; 'header:Reply-To:1': 0.68; 'received:74.208': 0.71; 'reply- to:no real name:2**0': 0.72; 'enforced': 0.84; 'received:74.208.4.194': 0.84; 'angel': 0.93
Date Mon, 26 Nov 2012 21:50:00 -0500
From Dave Angel <d@davea.name>
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:16.0) Gecko/20121011 Thunderbird/16.0.1
MIME-Version 1.0
To Ian Kelly <ian.g.kelly@gmail.com>
Subject Re: How to pass class instance to a method?
References <3193e3dd-0507-4ff7-9026-ee80e5d9c1dd@googlegroups.com> <pan.2012.11.26.16.56.29.389000@nowhere.com> <CALwzidn54ko2AGEj2QmanfFsoUBSqrNJ=TwNjCJt7-+_O2qu-w@mail.gmail.com> <50B3E617.3040302@davea.name> <CALwzidk6ntSbsYMQ4oWuXHYSk9NN5XWoJJRUeZqwgWo_P6RP6A@mail.gmail.com>
In-Reply-To <CALwzidk6ntSbsYMQ4oWuXHYSk9NN5XWoJJRUeZqwgWo_P6RP6A@mail.gmail.com>
Content-Type text/plain; charset=ISO-8859-1
Content-Transfer-Encoding 7bit
X-Provags-ID V02:K0:nBDwzgkaac0p4JLDBQoBt9pX87gHzF+r3OrBH/Cdj9M UyPCNwXU10Tjb2YtewdqSWXbdTXOh98W0qv30ubTRTpi/52Xp+ tnxVvg7xDrpIz3e70xklcexKemKrm5P2tocq4RS0daPXLHrPh5 2QZLcS7z2U0HdUjI9x3pXIeLGVyoNUJb6cj6h8Uzbb/cZISiKI +MMMYW93pOEMs7iB91pFStCdPxY0gZ4f5lmwRBJ3br8fWql5eD jRCn/xmfzbRY/Bw01715r171pF1n+wk8AmUlt5yvoBNlzZmdZ3 ERTk859j33EJAEvz8jXdMbgP5NeTZ2x3Xv8k5SHdtRHLWrcdg= =
Cc Python <python-list@python.org>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
Reply-To d@davea.name
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.306.1353984622.29569.python-list@python.org> (permalink)
Lines 31
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1353984622 news.xs4all.nl 6902 [2001:888:2000:d::a6]:54255
X-Complaints-To abuse@xs4all.nl
Path csiph.com!usenet.pasdenom.info!news.stben.net!border3.nntp.ams.giganews.com!border1.nntp.ams.giganews.com!border4.nntp.ams.giganews.com!border2.nntp.ams.giganews.com!nntp.giganews.com!feeder2.cambriumusenet.nl!feed.tweaknews.nl!194.109.133.83.MISMATCH!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Xref csiph.com comp.lang.python:33960

Show key headers only | View raw


On 11/26/2012 06:07 PM, Ian Kelly wrote:
> On Mon, Nov 26, 2012 at 2:58 PM, Dave Angel <d@davea.name> wrote:
>> Not how I would put it.  In a statically typed language, the valid types
>> are directly implied by the function parameter declarations,
> As alluded to in my previous post, not all statically typed languages
> require parameter type declarations to perform static checking.
>
>> while in a
>> dynamic language, they're defined in the documentation, and only
>> enforced (if at all) by the body of the function.
> That's not even true for Python.  The following example uses Python 2.x:
>
>>>> class Foo(object):
> ...     def method(self):
> ...         pass
> ...
>>>> Foo.method(4)
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
> TypeError: unbound method method() must be called with Foo instance as
> first argument (got int instance instead)
>
> That's a run-time check, and it's not enforced by the body of the function.

We were talking about function arguments.  I don't know of any place
where they get their types declared.

-- 

DaveA

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


Thread

How to pass class instance to a method? ALeX inSide <alex.b.inside@gmail.com> - 2012-11-25 04:11 -0800
  Re: How to pass class instance to a method? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-11-25 12:37 +0000
  Re: How to pass class instance to a method? Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2012-11-26 11:22 +1300
  Re: How to pass class instance to a method? Alain Ketterlin <alain@dpt-info.u-strasbg.fr> - 2012-11-26 11:08 +0100
  Re: How to pass class instance to a method? Nobody <nobody@nowhere.com> - 2012-11-26 16:56 +0000
    Re: How to pass class instance to a method? Ian Kelly <ian.g.kelly@gmail.com> - 2012-11-26 13:51 -0700
    Re: How to pass class instance to a method? Dave Angel <d@davea.name> - 2012-11-26 16:58 -0500
      Re: How to pass class instance to a method? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-11-26 22:18 +0000
        Re: How to pass class instance to a method? Dave Angel <d@davea.name> - 2012-11-26 22:14 -0500
          Re: How to pass class instance to a method? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-11-27 04:10 +0000
            Re: How to pass class instance to a method? Roy Smith <roy@panix.com> - 2012-11-26 23:25 -0500
            Re: How to pass class instance to a method? Dave Angel <d@davea.name> - 2012-11-27 00:18 -0500
    Re: How to pass class instance to a method? Ian Kelly <ian.g.kelly@gmail.com> - 2012-11-26 16:07 -0700
      Re: How to pass class instance to a method? Hans Mulder <hansmu@xs4all.nl> - 2012-11-27 01:36 +0100
    Re: How to pass class instance to a method? Dave Angel <d@davea.name> - 2012-11-26 21:50 -0500
  Re: How to pass class instance to a method? Drew <r.drew.davis@gmail.com> - 2012-11-26 17:14 -0800

csiph-web