473,320 Members | 2,122 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,320 software developers and data experts.

can not use __methods__

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

Jul 18 '05 #1
1 1332
aj****@gmail.com 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
Jul 18 '05 #2

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

Similar topics

8
by: Bo Peng | last post by:
Dear list, I am writing a Python extension module that needs a way to expose pieces of a big C array to python. Currently, I am using NumPy like the following: PyObject* res =...
0
by: Philippe C. Martin | last post by:
Is this possible ? I am trying to have auto-completion working in a shell I wrote but I currently have the method lists done by hand (ie; if I add/subtract a method from that class, then my...
0
by: Brock Filer | last post by:
> I personally would first try to dump the quotes and use standard > attributes -- countries.us.Colorado... -- and the __get/set/delattr__ > methods. If I do that, the attributes (that was a...
2
by: Attila Rajmund Nohl | last post by:
Hello! I'm using python 2.3.5 on Linux with omniORB 2.6. I'm trying to create an object that shall listen on an event channel, but the registration doesn't work. My code is: class...
5
by: John Salerno | last post by:
Hi everyone. I'm updating my UltraEdit syntax file for Python 2.5 and was wondering if anyone knew of other additions to make besides these. I found all of these in the What's New document, but...
20
by: walterbyrd | last post by:
Reading "Think Like a Computer Scientist" I am not sure I understand the way it describes the way objects work with Python. 1) Can attributes can added just anywhere? I create an object called...
9
by: Scott Huey | last post by:
I am working on a Python module and I would like to prepare some API documentaiton. I managed to find epydoc after some searching online. Is there a standard way to document the API for Python...
3
by: MisterPete | last post by:
I've run into this issue a couple of times. I want to inherit from a class in order to extend it's functionality. The problem is that the class is defined in c in a shared library and doesn't seem...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
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...
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)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
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
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.