python can't count!

Jay O'Connor joconnor at cybermesa.com
Thu Oct 2 11:09:31 EDT 2003


On 2 Oct 2003 08:02:48 -0700, dokaspar at student.ethz.ch (Dominik
Kaspar) wrote:

>hello
>
>i'm wondering if i'm just too stupid for python or if i've missed
>something fundamentally important of its semantics.
>Why does the following program result in the TypeError: print_it()
>takes exactly 1 argument (2 given)?
>I don't see any function passing or receiving 2 arguments here... am i
>blind?

You are missing the hidden passing of 'self' to object methods in
Python.  Methods need to declare 'self' in the parameter list

	...
	def print_it (self, n):
		print n
	...





>
>import threading
>
>class Server(threading.Thread):
>    def print_it(n):
>        print n
>
>    def run(self):
>        self.print_it(34)
>        while 1:
>            pass
>
>s = Server()
>s.start()





More information about the Python-list mailing list