473,574 Members | 2,465 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Determining method type given its string name presentation and its corresponding object reference.

Hi I am a bit new to python. I was wondering if there is a way to
determine whether or not a given string is a member method of a given
object:

def is_a_method(sel f, attr_name):
'returns True if attr_name is an instance method of self; false
otherwise'

The problem is that I have overridden __repr__ in such a way that it's
not self-contained. It makes a call to a member method, call it m(),
that would call up getattr() which eventually makes another call back
to __repr__:

Example output:
(<bound method Class.attr_name of "INSTANCE'S __repr__() HERE">).
So, I want to trap all attr_name that are methods comeing into m() and
make sure they're not passed on to getatrr() i.e. making __repr__
self-contained (hopefully).

Is there a simple way to determine a given attr_name is_a_method()?
Thanks in advance for all your help.

Jul 31 '05 #1
3 1451

"Apple" <ne**********@g mail.com> wrote in message
news:11******** **************@ g14g2000cwa.goo glegroups.com.. .
Hi I am a bit new to python. I was wondering if there is a way to
determine whether or not a given string is a member method of a given
object:


Does callable(cls.at tr) fit your needs?

Terry J. Reedy

Aug 1 '05 #2
Terry Reedy wrote:
"Apple" <ne**********@g mail.com> wrote in message
news:11******** **************@ g14g2000cwa.goo glegroups.com.. .
Hi I am a bit new to python. I was wondering if there is a way to
determine whether or not a given string is a member method of a given
object:

Does callable(cls.at tr) fit your needs?


or perhaps callable(getatt r(obj, strg, None)) if the need is related to
an unknown string which may be a callable attribute of an object whose
class is unknown ...
Aug 1 '05 #3
"or perhaps callable(getatt r(obj, strg, None)) if the need is related
to
an unknown string which may be a callable attribute of an object whose
class is unknown ..."

Hm.. the problem is I cannot call getattr() at all. Because getattr()
will call my __repr__() which will call another m() that will
eventually call getattr() again.. It's an infinite recursion. In
general, I think every time you try to qualify a method attribute, e.g.
obj.method, it'd actually end up making a call to __repr__()...

obj.method would usually get you this output:
(<bound method Class_of_obj.me thod of "INSTANCE'S __repr__() CALL
HERE">)

More or less I am trying to understand what getattr did to figure out
the name "method" is actually a method (bounded or not). This way I
can avoid the recursive call to __repr__(). I hope this clarifies my
question a bit?

Thanks a lot for the help ;)

Aug 1 '05 #4

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

Similar topics

8
2524
by: Mark English | last post by:
I'd like to write a Tkinter app which, given a class, pops up a window(s) with fields for each "attribute" of that class. The user could enter values for the attributes and on closing the window would be returned an instance of the class. The actual application I'm interested in writing would either have simple type attributes (int, string,...
6
22502
by: Martin | last post by:
I'd like to be able to get the name of an object instance from within a call to a method of that same object. Is this at all possible? The example below works by passing in the name of the object instance (in this case 'myDog'). Of course it would be better if I could somehow know from within write() that the name of the object instance was...
2
3632
by: Garrett | last post by:
Need any help in determining which groups have been given security access to a folder. Searched DirectoryServices to no avail... Any Help?
24
2591
by: ALI-R | last post by:
Hi All, First of all I think this is gonna be one of those threads :-) since I have bunch of questions which make this very controversial:-0) Ok,Let's see: I was reading an article that When you pass a Value-Type to method call ,Boxing and Unboxing would happen,Consider the following snippet: int a=1355; myMethod(a); ......
0
2234
by: Cleo | last post by:
Hi, I am trying to call a WebService Method written in Weblogic from VB.NET and I am getting the following error. I am using SOAP Caal s from VB.NET. Please find the wsdl file and my code. Any help would really be appreciated. Thx
7
4739
by: John Grandy | last post by:
My ASP.NET Web Service project has a Web Method that returns an array filled with instances of a custom class. The custom class is defined in a Class Library that is included in the web-service project. The same class lib is included in the ASP.NET Web Application that calls the web-method I can successfully call the web-method with
7
11930
by: Martin Robins | last post by:
I am currently looking to be able to read information from Active Directory into a data warehouse using a C# solution. I have been able to access the active directory, and I have been able to return "DirectoryEntry" objects within the path that I specify (either using the DirectoryEnrtry.Children or using the DirectorySearcher class) and all...
19
2422
by: zzw8206262001 | last post by:
Hi,I find a way to make javescript more like c++ or pyhon There is the sample code: function Father(self) //every contructor may have "self" argument { self=self?self:this; //every class may have this statement self.hello = function() {
0
7710
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8040
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7800
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8092
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6437
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5296
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3745
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2230
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1051
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.