What's wrong?
Fredrik Lundh
effbot at telia.com
Sun Oct 8 05:58:58 EDT 2000
"root" wrote:> from window1Handlers import *
> class window1Widget:
> def add_col(co=[]):
> for cc in co:
> print cc
> self.li=GtkListItem('123')
> self.list1.add(self.li)
> self.li.show()
>
> def download_process(xxxxxx=None):
> print 'now working'
> homedir = '.'
> main_url = 'http://www.findserendipity.com/'
> #main_page = urllib.urlopen(main_url+'collections.html').read()
> main_page = open('cool.html').read()
> mainpars = extract_links(main_page)
> collections = no_doubles(select_html(mainpars.anchorlist))
> self.add_col(collections) # WHY this is an error? (Name Error: self)
short answer: change your method declarations to:
def add_col(self, co=[])
def download_process(self, xxxxxx=None)
longer answer: python's not C++, and there's no automatic this/self
variable. instead, the instance is passed as the first argument to the
method.
also see the tutorial, and FAQ entry 4.21 and 6.7:
http://www.python.org/doc/FAQ.html#4.21
"what is self?"
http://www.python.org/doc/FAQ.html#6.7
"Why must 'self' be declared and used explicitly in
method definitions and calls?"
</F>
<!-- (the eff-bot guide to) the standard python library:
http://www.pythonware.com/people/fredrik/librarybook.htm
-->
More information about the Python-list
mailing list