Matt McCredie
1/14/2008 9:51:00 PM
On Jan 14, 1:20 pm, jerryji <jerryji1...@gmail.com> wrote:
> Hi,
>
> Sorry for this newbie question, I was puzzled why the existing
> property of an object is not shown in the dir() function output.
>
> "v" is an lxml Element object variable --
>
> In [44]: v
> Out[44]: <Element 'documentProperties' at 0x8363cf8>
>
> In [45]: dir(v)
> Out[45]:
> ['__copy__',
> '__deepcopy__',
> '__reduce__',
> 'append',
> 'clear',
> 'find',
> 'findall',
> 'findtext',
> 'get',
> 'getchildren',
> 'getiterator',
> 'insert',
> 'items',
> 'keys',
> 'makeelement',
> 'remove',
> 'set']
>
> dir() output doesn't contain the ".tag", which does exist --
>
> In [46]: v.tag
> Out[46]: 'documentProperties'
>
> what is the rule governing the display of a property from dir()?
You can also make properties by modifying the __getattr__ and
__setattr__ methods of a class. When done that way it won't show up
when dir is called. So it isn't necessarily a rule, just a different
way of implementing a property.
Matt