Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #13312
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!feeder.erje.net!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <chris@rebertia.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.031 |
| X-Spam-Evidence | '*H*': 0.94; '*S*': 0.00; 'instance': 0.05; 'definitions': 0.07; 'skip:l 60': 0.09; 'subject:method': 0.09; 'run(self):': 0.16; 'skip:# 60': 0.16; 'subject:wrong': 0.16; 'cc:addr:python-list': 0.16; 'cheers,': 0.18; 'trying': 0.21; 'cc:2**0': 0.22; 'header:In-Reply-To:1': 0.22; 'code.': 0.26; 'skip:_ 20': 0.28; 'message-id:@mail.gmail.com': 0.29; 'fix': 0.29; 'cc:addr:python.org': 0.30; '\xc2\xa0\xc2\xa0\xc2\xa0': 0.30; 'class': 0.30; 'error': 0.32; 'chris': 0.32; 'point,': 0.32; "can't": 0.33; 'there': 0.33; 'assignment': 0.34; 'executable': 0.34; 'object': 0.35; 'class.': 0.37; 'received:google.com': 0.38; 'subject:: ': 0.39; 'why': 0.39; 'received:74.125': 0.39; "it's": 0.40; 'happens': 0.40; 'sender:addr:chris': 0.84; 'url:rebertia': 0.84; '\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0': 0.84; 'subject::': 0.87; 'to:none': 0.93 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=rebertia.com; s=google; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:cc:content-type :content-transfer-encoding; bh=n5gTRDsg2t2ne/f/O5DNfspmV14knhvE2mGbGds/hmM=; b=SjQCLGr8Bm57d9j+t+FUkuRyFhfVMDzb1Ojq4j3d60OTu7yvSN2lOdroxDvRS9JpbX nmQOgIWOkKAr0n2xIjkoCkk9m4NLZ0IIh6QZ9FNfvEtjjuaxDq9fOvb7XI9CAdQ/BEfe GYAbOqNSlpdHaptVCEQ6nfWD0HqdZ9lJhJZJM= |
| MIME-Version | 1.0 |
| Sender | chris@rebertia.com |
| In-Reply-To | <tencent_7D324E33209E90851683965E@qq.com> |
| References | <tencent_7D324E33209E90851683965E@qq.com> |
| Date | Thu, 15 Sep 2011 01:39:48 -0700 |
| X-Google-Sender-Auth | z9gAkYwQjlLXAVxKhJdLalcDAHY |
| Subject | Re: method:wrong structure |
| From | Chris Rebert <clp2@rebertia.com> |
| Cc | python-list <python-list@python.org> |
| Content-Type | text/plain; charset=UTF-8 |
| Content-Transfer-Encoding | quoted-printable |
| 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.1155.1316075991.27778.python-list@python.org> (permalink) |
| Lines | 43 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1316075991 news.xs4all.nl 2451 [2001:888:2000:d::a6]:43150 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.python:13312 |
Show key headers only | View raw
2011/9/15 守株待兔 <1248283536@qq.com>:
> there are three programs,all of them left main structure,
> code0 is ok,i don't know why code2 and code3 can't run,how to fix them?
> code0
> class webdata(object):
> def __init__(self,arg):
>
> def loadequity(self):
>
> def loadoption(self):
>
> #loadstatus={'equity':self.loadequity(),'option':self,loadoption()}
>
> def run(self):
>
> if __name__=="__main__":
> s=webdata('equity').run()
> s.loadequity()
>
> code1
> class webdata(object):
> def __init__(self,arg):
>
> def loadequity(self):
>
> def loadoption(self):
>
> loadstatus={'equity':self.loadequity(),'option':self,loadoption()}
Class definitions are executable code. So the assignment to loadstatus
happens *while the class webdata is still being defined*. There is
therefore no class instance object or `self` at this point, hence the
error when you try and do self.loadequity(): you're trying to call an
instance method before it's even possible for there to be instances of
the class.
Cheers,
Chris
--
http://rebertia.com
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: method:wrong structure Chris Rebert <clp2@rebertia.com> - 2011-09-15 01:39 -0700
csiph-web