Package nltk :: Module internals :: Class ElementWrapper
[hide private]
[frames] | no frames]

Class ElementWrapper

source code

object --+
         |
        ElementWrapper

A wrapper around ElementTree Element objects whose main purpose is to provide nicer __repr__ and __str__ methods. In addition, any of the wrapped Element's methods that return other Element objects are overridden to wrap those values before returning them.

This makes Elements more convenient to work with in interactive sessions and doctests, at the expense of some efficiency.

Instance Methods [hide private]
 
__init__(self, etree)
Initialize a new Element wrapper for etree.
source code
 
unwrap(self)
Return the Element object wrapped by this wrapper.
source code

Inherited from object: __getattribute__, __hash__, __reduce__, __reduce_ex__

    String Representation
 
__repr__(self)
repr(x)
source code
 
__str__(self)
Returns: the result of applying ElementTree.tostring() to the wrapped Element object.
source code
    Element interface Delegation (pass-through)
 
__getattr__(self, attrib) source code
 
__setattr__(self, attr, value)
x.__setattr__('name', value) <==> x.name = value
source code
 
__delattr__(self, attr)
x.__delattr__('name') <==> del x.name
source code
 
__setitem__(self, index, element) source code
 
__delitem__(self, index) source code
 
__setslice__(self, start, stop, elements) source code
 
__delslice__(self, start, stop) source code
 
__len__(self) source code
    Element interface Delegation (wrap result)
 
__getitem__(self, index) source code
 
__getslice__(self, start, stop) source code
 
getchildren(self) source code
 
getiterator(self, tag=None) source code
 
makeelement(self, tag, attrib) source code
 
find(self, path) source code
 
findall(self, path) source code
Static Methods [hide private]
a new object with type S, a subtype of T
__new__(cls, etree)
Create and return a wrapper around a given Element object.
source code
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__new__(cls, etree)
Static Method

source code 

Create and return a wrapper around a given Element object. If etree is an ElementWrapper, then etree is returned as-is.

Returns: a new object with type S, a subtype of T
Overrides: object.__new__

__init__(self, etree)
(Constructor)

source code 

Initialize a new Element wrapper for etree. If etree is a string, then it will be converted to an Element object using ElementTree.fromstring() first.

Overrides: object.__init__

__repr__(self)
(Representation operator)

source code 

repr(x)

Overrides: object.__repr__
(inherited documentation)

__str__(self)
(Informal representation operator)

source code 

str(x)

Returns:
the result of applying ElementTree.tostring() to the wrapped Element object.
Overrides: object.__str__

__setattr__(self, attr, value)

source code 

x.__setattr__('name', value) <==> x.name = value

Overrides: object.__setattr__
(inherited documentation)

__delattr__(self, attr)

source code 

x.__delattr__('name') <==> del x.name

Overrides: object.__delattr__
(inherited documentation)