Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #21092
| Path | csiph.com!aioe.org!newsfeed.x-privat.org!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <arnodel@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.048 |
| X-Spam-Evidence | '*H*': 0.90; '*S*': 0.00; 'exec': 0.07; 'received:209.85.214.174': 0.13; '13:07,': 0.16; 'a()': 0.16; 'cc:addr:python-list': 0.16; 'this:': 0.16; 'wrote:': 0.18; 'arguments': 0.18; 'cc:no real name:2**0': 0.21; 'header:In-Reply- To:1': 0.22; 'cc:2**0': 0.26; "i'm": 0.28; 'message- id:@mail.gmail.com': 0.29; 'class': 0.29; 'print': 0.29; 'cc:addr:python.org': 0.29; 'cmd': 0.30; 'does': 0.32; 'this.': 0.33; 'hi,': 0.34; 'curious': 0.34; 'received:209.85.214': 0.36; 'but': 0.37; 'received:google.com': 0.37; 'using': 0.37; 'skip:_ 10': 0.38; 'received:209.85': 0.38; 'doing': 0.38; 'received:209': 0.39; 'header:Received:6': 0.61; 'your': 0.61; 'march': 0.61; 'works,': 0.68; 'wester': 0.84 |
| Received-SPF | pass (google.com: domain of arnodel@gmail.com designates 10.182.75.40 as permitted sender) client-ip=10.182.75.40; |
| Authentication-Results | mr.google.com; spf=pass (google.com: domain of arnodel@gmail.com designates 10.182.75.40 as permitted sender) smtp.mail=arnodel@gmail.com; dkim=pass header.i=arnodel@gmail.com |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; bh=/WsGcRHZk/1a8a2wEJUzwlHHwfkqoMfgOELFZPAgyow=; b=sq6siu+uIMyJWa54cqI7oBMVjsEpowLV75Wdm2GntWkZy0DlGkmGRAgf1zQv5HQL56 hjK17jfJh+C9SAdGADtblQcNJ6D8if4q3Lvyhq9nEXxwAUrmn/o8QyUdY6iM7hO5Xozz woc0E1G+yVu1Cq7sgT89wqKoq1LidN/fVjCSY= |
| MIME-Version | 1.0 |
| In-Reply-To | <4f4f7527$1@news.fhg.de> |
| References | <4f4f7527$1@news.fhg.de> |
| Date | Thu, 1 Mar 2012 14:13:39 +0000 |
| Subject | Re: exec |
| From | Arnaud Delobelle <arnodel@gmail.com> |
| To | Rolf Wester <rolf.wester@ilt.fraunhofer.de> |
| Content-Type | text/plain; charset=UTF-8 |
| Content-Transfer-Encoding | quoted-printable |
| Cc | python-list@python.org |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.12 |
| 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.322.1330611223.3037.python-list@python.org> (permalink) |
| Lines | 21 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1330611223 news.xs4all.nl 6978 [2001:888:2000:d::a6]:36433 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:21092 |
Show key headers only | View raw
On 1 March 2012 13:07, Rolf Wester <rolf.wester@ilt.fraunhofer.de> wrote: > Hi, > > I would like to define methods using exec like this: > > class A: > def __init__(self): > cmd = "def sqr(self, x):\n return x**2\nself.sqr = sqr\n" > exec cmd > a = A() > print a.sqr(a, 2) > > This works, but I have to call sqr with a.sqr(a, 2), a.sqr(2) does not work > (TypeError: sqr() takes exactly 2 arguments (1 given)). I'm curious to know your motivation for doing this. -- Arnaud
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
exec Rolf Wester <rolf.wester@ilt.fraunhofer.de> - 2012-03-01 14:07 +0100
Re: exec Jean-Michel Pichavant <jeanmichel@sequans.com> - 2012-03-01 14:46 +0100
Re: exec Arnaud Delobelle <arnodel@gmail.com> - 2012-03-01 14:13 +0000
Re: exec Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-03-01 14:21 +0000
Re: exec Rolf Wester <rolf.wester@ilt.fraunhofer.de> - 2012-03-01 16:58 +0100
Re: exec Michael Ströder <michael@stroeder.com> - 2012-03-01 17:26 +0100
Re: exec Peter Otten <__peter__@web.de> - 2012-03-01 18:14 +0100
Re: exec Rolf Wester <rolf.wester@ilt.fraunhofer.de> - 2012-03-01 18:23 +0100
Re: exec Peter Otten <__peter__@web.de> - 2012-03-02 08:26 +0100
csiph-web