Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > can not use __methods__

Reply
Thread Tools

can not use __methods__

 
 
ajikoe@gmail.com
Guest
Posts: n/a
 
      01-26-2005
Hello,

I try to use __methods__ in python 2.4 and 2.2 it always fail.
Can some one tell me if I want to itterate the methods in a class and
print it in a string format ( it is possible using __methods__ ).
Is there any replacement?

Sincerely Yours,
Pujo

 
Reply With Quote
 
 
 
 
Steven Bethard
Guest
Posts: n/a
 
      01-26-2005
wrote:
> I try to use __methods__ in python 2.4 and 2.2 it always fail.
> Can some one tell me if I want to itterate the methods in a class and
> print it in a string format ( it is possible using __methods__ ).
> Is there any replacement?


py> class C(object):
.... a = 1
.... b = 2
.... def f(self):
.... pass
.... def g(self):
.... pass
....
py> import inspect
py> for attr, value in C.__dict__.iteritems():
.... if inspect.isroutine(value):
.... print attr, value
....
g <function g at 0x00C10B70>
f <function f at 0x011AC4B0>

or:

py> for attr, value in vars(C).iteritems():
.... if inspect.isroutine(value):
.... print attr, value
....
g <function g at 0x00C10B70>
f <function f at 0x011AC4B0>

or if you want to include special methods:

py> for attr in dir(C):
.... value = getattr(C, attr)
.... if inspect.isroutine(value):
.... print attr, value
....
__delattr__ <slot wrapper '__delattr__' of 'object' objects>
__getattribute__ <slot wrapper '__getattribute__' of 'object' objects>
__hash__ <slot wrapper '__hash__' of 'object' objects>
__init__ <slot wrapper '__init__' of 'object' objects>
__new__ <built-in method __new__ of type object at 0x1E1AE6E8>
__reduce__ <method '__reduce__' of 'object' objects>
__reduce_ex__ <method '__reduce_ex__' of 'object' objects>
__repr__ <slot wrapper '__repr__' of 'object' objects>
__setattr__ <slot wrapper '__setattr__' of 'object' objects>
__str__ <slot wrapper '__str__' of 'object' objects>
f <unbound method C.f>
g <unbound method C.g>

This is probably useful for introspection at the Python prompt, but if
you're planning on doing this in your code somewhere, you might present
the problem you're trying to solve to the list, because this is likely
not the best way to approach it...

Steve
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
If I use the WAP add-on, can I not use GridView paging and sorting? Chris S ASP .Net 0 12-13-2006 10:03 PM
Do U use >>>>>perl -e 'use re debug;/REGEX/' so U can help?? robertospara Perl Misc 14 12-10-2006 10:45 AM
How can I use switch -s and 'use strict' at the same time Ting Wang Perl Misc 5 10-06-2005 02:03 PM
Can I use use Microsoft Masked Edit Control in ASP.NET web form =?Utf-8?B?ZGF2aWQ=?= ASP .Net 1 04-19-2005 01:12 AM
Can I use XPath or something to a remote Mac or Linux box and just query an xml file, not using web services and use encyrption? jake ASP .Net 0 07-06-2004 02:16 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57