473,327 Members | 2,074 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

method in the definiton of a methond


I've a clas with following methods:

class difracsocket:
def __init__(self,sock=None):
self.Handle = 1
[...]

def cliente(self,orden,respuesta):
[...]

def GetNewHandle(self):
newhandle = self.Handle
newhandle += 1
if newhandle > MAXHANDLE:
newhandle = 1
self.Handle = newhandle
return newhandle

def Move(self, table, angle,handle=1):
orden = instruccion(handle)
respuesta = instruccion
orden.Codigo = 6
Comando = "mvr "
if table == "TTH" or "tth":
Comando += "tth "
elif table == "TH" or "th":
Comando += "th "
Comando += str(angle)
orden.Comando = Comando
self.cliente(orden,respuesta)
return respuesta

I what to change de definiton of Move to something like
def Move(self, table, angle,handle=self.GetNewHandle)
File "comunicacion.py", line 201, in difracsocket
def Move(self,handle=self.GetNewHandle()):
NameError: name 'self' is not defined

Any hit? Can't i invoke methods in the definition of other methods?
Thanks in advance

Zunbeltz
--
Remove XXX from email: zu******@wm.lc.ehu.esXXX
Jul 18 '05 #1
3 3186
On 29 Oct 2003 12:22:11 +0100, Zunbeltz Izaola
<zu******@wm.lc.ehu.es.XXX> wrote:

[text snipped]

I what to change de definiton of Move to something like
def Move(self, table, angle,handle=self.GetNewHandle)
File "comunicacion.py", line 201, in difracsocket
def Move(self,handle=self.GetNewHandle()):
NameError: name 'self' is not defined


The traceback tells it all: self is not defined. self is *local* to
the Move method itself. You can't access it from the outside which is
what you are trying to do, by putting it in the args list for Move.

The following should work

def Move(self,handle = None):
if handle is None:
handle = self.GetNewHandler()
etc,...

With my best regards,
G. Rodrigues
Jul 18 '05 #2
Gonçalo Rodrigues <op*****@mail.telepac.pt> writes:
The traceback tells it all: self is not defined. self is *local* to
the Move method itself. You can't access it from the outside which is
what you are trying to do, by putting it in the args list for Move.

The following should work

def Move(self,handle = None):
if handle is None:
handle = self.GetNewHandler()
etc,...

With my best regards,
G. Rodrigues


Thanks for the answer. I'm understanding python better every time i
read c.l.p :-)

Zunbeltz
--
Remove XXX from email: zu******@wm.lc.ehu.esXXX
Jul 18 '05 #3

"Zunbeltz Izaola" <zu******@wm.lc.ehu.es.XXX> wrote in message
news:m1************@lcpxdf.wm.lc.ehu.es...
I what to change de definiton of Move to something like
def Move(self, table, angle,handle=self.GetNewHandle):


The def header, including default arg expression, is 'executed' to
construct the function and is not part of the body executed when the
constructed function is executed. When the function is created,
'self' is just a name not yet bould to anything. What you want is
....handle = None): followed by
a first line of 'if handle == None: handle = self.GetNewHandle'.

Terry J. Reedy

Jul 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Edward Diener | last post by:
This simple code example gives me the message, "TypeError: 'staticmethod' object is not callable". class X(object): def Y(x): print x Y = staticmethod(Y) ad = { 1 : Y } def Z(self):...
31
by: Chris S. | last post by:
Is there a purpose for using trailing and leading double underscores for built-in method names? My impression was that underscores are supposed to imply some sort of pseudo-privatization, but would...
2
by: Marcin | last post by:
Hello! Is there any method to detect parameters values passed to called method? For example: public Guid ApplicationLogin(string userName, string password, int dbId)
11
by: Dave Rahardja | last post by:
OK, so I've gotten into a philosophical disagreement with my colleague at work. He is a proponent of the Template Method pattern, i.e.: class foo { public: void bar() { do_bar(); } protected:...
5
by: Chris | last post by:
Hi I have a scenario where I've created another AppDomain to dynamically load a DLL(s) into. In this newly loaded DLL I want to call a static method on a class. The problem arise is that I have...
1
by: Oriane | last post by:
Hi, I'm currently a method attribute which is used to check the "validity" of this method against a rule. I wrote the isValid method, to be used inside the otriginal method: For instance: //...
4
by: daniel.w.gelder | last post by:
I wrote a template class that takes a function prototype and lets you store and call a C-level function, like this: inline string SampleFunction(int, bool) {..} functor<string (int, bool)>...
7
by: greenflame | last post by:
I am trying to make a matrix object. I have given it some properites. I am trying to add a method. When I call the method by Test.showDims(...) I want to only enter one input, that is the method by...
9
by: Mwob | last post by:
Hi, I have a very simple function, declared like this: wstring CMyClass::GetDate() { .... wcsftime (sDateString,255,L"%d-%b-%Y",&dTmpDate); wstring sText(sDateString); return sText;
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.