|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
my socket class: getting a strange error regarding my methods
okay, so the code is below. when i run it coupled with the following test code, I get the following error.
PHP Code:
PHP Code:
Code:
Traceback (most recent call last):
File "C:\Documents and Settings\Daniel\Desktop\python\class_socket.py", line 67, in ?
sock.bind( 'localhost' , 5376 )
TypeError: unbound method bind() must be called with NewSock instance as first argument (got str instance instead)
I'm not sure what to do, at all, could someone help? Thanks. |
|
#2
|
|||
|
|||
|
You're missing the parentheses. You need to use
Code:
sock = NewSock() to create an instance of NewSock. |
|
#3
|
|||
|
|||
|
oh! omfg, my mistake. thanks alot
![]() |
|
#4
|
|||
|
|||
|
damnit, now i get this error:
Code:
Traceback (most recent call last):
File "C:\Documents and Settings\Daniel\Desktop\python\class_socket.py", line 67, in ?
sock.bind('localhost',5376)
TypeError: bind() takes exactly 2 arguments (3 given)
that can't be right, look at the code (oh, ignore the multiple usernames. the software screwed up my other one.) |
|
#5
|
||||
|
||||
|
When you define a method you need to add an extra paramater before your arguments, which will refer to that class instance itself. In Python this is called self, though technically you can use any name you want. But its a good idea to follow the standards where you can
.So. Code:
def bind( host , port ): becomes, Code:
def bind(self, host, port): etc. Hope this helps, Mark. Last edited by netytan : July 27th, 2004 at 07:08 AM. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Python Programming > my socket class: getting a strange error regarding my methods |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|