Monday, July 22, 2013

Python, show methods for a class, and type of an object

use "inspect", "type" and __class__

here an example:

from xml.dom import minidom
aproxy='someps.proxy'
xmldoc = minidom.parse(aproxy)
route=xmldoc.getElementsByTagNameNS("http://www.bea.com/wli/sb/stages/publish/config", 'route')[0]

print type(route)
<type 'instance'>

print route.__class__
xml.dom.minidom.Element

import inspect
inspect.getmembers(route, predicate=inspect.ismethod)
 
[('__init__', <method Element.__init__ of Element instance 2>), ('__nonzero__', <method Element.__nonzero__ of Element instance 2>), ('__repr__', <method Element.__repr__ of Element instance 2>), ('_call_user_data_handler', <method Element._call_user_data_handler of Element instance 2>), ('_get_attributes', <method Element._get_attributes of Element instance 2>), ('_get_childNodes', <method Element._get_childNodes of Element instance 2>), ('_get_firstChild', <method Element._get_firstChild of Element instance 2>), ('_get_lastChild', <method Element._get_lastChild of Element instance 2>), ('_get_localName', <method Element._get_localName of Element instance 2>), ('_get_tagName', <method Element._get_tagName of Element instance 2>), ('appendChild', <method Element.appendChild of Element instance 2>), ('cloneNode', <method Element.cloneNode of Element instance 2>), ('getAttribute', <method Element.getAttribute of Element instance 2>), ('getAttributeNS', <method Element.getAttributeNS of Element instance 2>), ('getAttributeNode', <method Element.getAttributeNode of Element instance 2>), ('getAttributeNodeNS', <method Element.getAttributeNodeNS of Element instance 2>), ('getElementsByTagName', <method Element.getElementsByTagName of Element instance 2>), ('getElementsByTagNameNS', <method Element.getElementsByTagNameNS of Element instance 2>), ('getInterface', <method Element.getInterface of Element instance 2>), ('getUserData', <method Element.getUserData of Element instance 2>), ('hasAttribute', <method Element.hasAttribute of Element instance 2>), ('hasAttributeNS', <method Element.hasAttributeNS of Element instance 2>), ('hasAttributes', <method Element.hasAttributes of Element instance 2>), ('hasChildNodes', <method Element.hasChildNodes of Element instance 2>), ('insertBefore', <method Element.insertBefore of Element instance 2>), ('isSameNode', <method Element.isSameNode of Element instance 2>), ('isSupported', <method Element.isSupported of Element instance 2>), ('normalize', <method Element.normalize of Element instance 2>), ('removeAttribute', <method Element.removeAttribute of Element instance 2>), ('removeAttributeNS', <method Element.removeAttributeNS of Element instance 2>), ('removeAttributeNode', <method Element.removeAttributeNode of Element instance 2>), ('removeAttributeNodeNS', <method Element.removeAttributeNode of Element instance 2>), ('removeChild', <method Element.removeChild of Element instance 2>), ('replaceChild', <method Element.replaceChild of Element instance 2>), ('setAttribute', <method Element.setAttribute of Element instance 2>), ('setAttributeNS', <method Element.setAttributeNS of Element instance 2>), ('setAttributeNode', <method Element.setAttributeNode of Element instance 2>), ('setAttributeNodeNS', <method Element.setAttributeNode of Element instance 2>), ('setIdAttribute', <method Element.setIdAttribute of Element instance 2>), ('setIdAttributeNS', <method Element.setIdAttributeNS of Element instance 2>), ('setIdAttributeNode', <method Element.setIdAttributeNode of Element instance 2>), ('setUserData', <method Element.setUserData of Element instance 2>), ('toprettyxml', <method Element.toprettyxml of Element instance 2>), ('toxml', <method Element.toxml of Element instance 2>), ('unlink', <method Element.unlink of Element instance 2>), ('writexml', <method Element.writexml of Element instance 2>)]

No comments: