[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.python

hide object property from dir() function?

jerryji

1/14/2008 9:20:00 PM

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()?

Many thanks in advance!

Jerry
3 Answers

Matt McCredie

1/14/2008 9:51:00 PM

0

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

Tim Golden

1/15/2008 9:06:00 AM

0

jerryji wrote:
> Sorry for this newbie question, I was puzzled why the existing
> property of an object is not shown in the dir() function output.

The under-development version of Python (2.6) allows for a
__dir__ magic method by which the class implementer can
return whatever he wishes from a dir (). This is to help,
for example, modules like my WMI one which makes heavy use
of __getattr__ magic to proxy across Windows COM attributes.
This, in turn, helps editors and IDEs which can provide
popup lists of attributes etc.

All that said, I don't believe it takes any automatic
account of properties.

TJG

<noddy code example>
class X (object):
def __init__ (self, a):
self.a = a

print dir (X (1))

def __dir__ (self):
return ['x', 'y', 'z']

X.__dir__ = __dir__

print dir (X (2))

</code>

Bobby Conover

2/8/2011 1:56:00 AM

0

It's really hard to pit Funhouse against any other pin because its
strengths lay more in the game being a complete package -- a unique,
charming little piece of entertainment -- than being an incredibly
deep pinball machine. There is no doubt that the first day you own it,
possibly on your first game, you will see 95% of everything the game
has to offer rules-wise. It just happens to nail everything so
perfectly, particularly the music/sound and integration of Rudy, that
it's very easy to fall in love with it despite its pretty shallow
ruleset. For me it was the first pinball machine I got truly addicted
to, and despite having much less interest in playing it for score now,
it will most likely never leave my collection. It's hard not to smile
when you start up a game and hear Rudy's voice, even if it's for the
5000th time. It's probably the only pin where it truly feels like
you're playing against a character. No Fear, Black Knight, Road Show
and many others have tried and haven't quite gotten it right, and
that's coming from a fan of all of those games.

NGG has more to shoot for, better flow, fun toys, etc, and it's
definitely one I want to pick up someday. I wouldn't say it's a
classic like Funhouse, but it probably has more "staying power" if
sheer volume of stuff to do is your main concern. For me, Funhouse
will always have more staying power because it's simply a special game
that feels unlike all others.