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


Groups > comp.lang.python > #13312 > unrolled thread

Re: method:wrong structure

Started byChris Rebert <clp2@rebertia.com>
First post2011-09-15 01:39 -0700
Last post2011-09-15 01:39 -0700
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: method:wrong structure Chris Rebert <clp2@rebertia.com> - 2011-09-15 01:39 -0700

#13312 — Re: method:wrong structure

FromChris Rebert <clp2@rebertia.com>
Date2011-09-15 01:39 -0700
SubjectRe: method:wrong structure
Message-ID<mailman.1155.1316075991.27778.python-list@python.org>
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

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web