0

Hi!

I have a class:

class A(object):
  calledMethod = None
  def a1(self):
    pass
  def a2(self):
    pass

Now when I create an object and call some method:

a = A()
a.a1()
#or
a.a2()

I need somehow to save the name of called method in variable calledMethod. Could this be done with descriptors? That will be the best way since I dont want to put extra code in every method to find its name...

Thanks

2
Contributors
2
Replies
3
Views
9 Years
Discussion Span
Last Post by bosko
0

This is odd. Each method already knows its own name. For example:

class A(object):

  def a1(self):
      self.calledMethod = "a1"

  def a2(self):
      self.calledMethod = "a2"

That is, when you call a function or method, the instruction pointer knows which code block it's currently in.

So what is it that you want to do with these names?

Confused,
Jeff

0

Hi!

Well, that's exactly the solution that I was trying to avoid. I don't want to put code in every method to assign that method name to calledMethod variable. Let's say that I have a 30 different classes where each of them can have many methods. In that case I'll have to put in every single method an assignment to variable calledMethod. That seems to me like a waste of code. I would like a solution where every class would have a same parent class with some code(descriptors?) which can track every method call and put called method name into variable calledMethod.
Anyway thanks.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.