How do I declare global vars or class vars in Python ?

Paddy O'Loughlin patrick.oloughlin at gmail.com
Fri Feb 20 19:45:16 CET 2009


2009/2/20 Bruno Desthuilliers <bruno.42.desthuilliers at websiteburo.invalid>:
> Check by yourself:
>
>>>> import inspect
>>>> inspect.isfunction(property)
> False
Using this, every single builtin function returns False. That's a
pretty limited definition to be being pedantic over, especially when
they are in the "Built-in Functions" section of the manual.

>>>> property()
> <property object at 0xb7cbc144>
I never said that calling it didn't return a property object :)

>>> property
<type 'property'>

So it's a type.
I think I didn't make such a bad error on my part. My intent in what I
was saying was to indicate that I hadn't created a property type. It's
fair enough to consider type constructors as functions given how they
are listed as such by the python documentation.
I don't think that your correction was much help, unless you just want
to say that everything is an object. Maybe you'd be right, but it's
not much use to use the term that way, imo

<shrug>

>>>> dir(property)
> ['__class__', '__delattr__', '__delete__', '__doc__', '__get__',
> '__getattribute__', '__hash__', '__init__', '__new__', '__reduce__',
> '__reduce_ex__', '__repr__', '__set__', '__setattr__', '__str__', 'fdel',
> 'fget', 'fset']

Doesn't prove a whole lot. So types have attributes...
So do functions:
>>> def myfunc():
...     pass
...
>>> dir(myfunc)
['__call__', '__class__', '__delattr__', '__dict__', '__doc__',
'__get__', '__getattribute__', '__hash__', '__init__', '__module__',
'__name__', '__new__', '__reduce__', '__reduce_ex__', '__repr__',
'__setattr__', '__str__', 'func_closure', 'func_code',
'func_defaults', 'func_dict', 'func_doc', 'func_globals', 'func_name']


>> Hmm, it doesn't seem to me like it's much of a big deal, for it to
>> described as anything like a "GoldenRule"
>
> One could say the same for each and any of the usual GoldenRules(tm).
Not really. To do so would be over-generalising and not useful to discussion
I guess it's your pedantry that I'm questioning.
Something like "don't use goto's" works as a GoldenRule because it's
been observed that without it, people start using goto statements in
places where it's not really appropriate.
When you said that "[you] usually shouldn't [use properties] - unless
you have a very compelling reason", your tone implied that properties
are easy to misuse and tend to be.
Not being familiar with properties and seeing them as being pretty
harmless, I was intrigued by this, which is why I asked for an
explanation.
Your explanation seems to show that your tone was likely to be more
personal bias than any real issue with properties.

Paddy

-- 
"Ray, when someone asks you if you're a god, you say YES!"



More information about the Python-list mailing list