Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #8923
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!selfless.tophat.at!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <python-python-list@m.gmane.org> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.002 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'attributes': 0.05; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:80.91.229.12': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'received:lo.gmane.org': 0.09; 'subject:Extracting': 0.09; '@property': 0.16; 'instances.': 0.16; 'naming': 0.16; 'obj,': 0.16; 'out?': 0.16; 'subject:() ': 0.16; 'classes,': 0.16; 'method.': 0.16; 'this:': 0.16; '>>>': 0.16; 'def': 0.16; 'header:In-Reply-To:1': 0.22; 'parse': 0.23; 'skip:[ 10': 0.26; 'string': 0.26; 'import': 0.29; 'variables': 0.29; 'module': 0.30; 'easier.': 0.30; 'class': 0.31; 'print': 0.32; "won't": 0.32; 'list': 0.32; 'does': 0.32; 'to:addr:python-list': 0.34; 'header:X-Complaints-To:1': 0.34; 'header:User-Agent:1': 0.34; 'there': 0.34; 'some': 0.37; 'several': 0.37; 'using': 0.37; 'received:org': 0.38; 'subject:: ': 0.38; 'header:Mime-Version:1': 0.39; 'skip:v 20': 0.39; 'subject:from': 0.39; 'help': 0.39; 'to:addr:python.org': 0.39; 'delete': 0.40; 'property': 0.65; 'here.': 0.66; 'inspection': 0.67; 'schrieb': 0.84 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| To | python-list@python.org |
| From | Christian Heimes <lists@cheimes.de> |
| Subject | Re: Extracting property getters from dir() results |
| Date | Wed, 06 Jul 2011 11:35:18 +0200 |
| References | <433563dc-b5bb-42f1-9023-3ec799d25505@k13g2000vbv.googlegroups.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=ISO-8859-1 |
| Content-Transfer-Encoding | 7bit |
| X-Gmane-NNTP-Posting-Host | f049079068.adsl.alicedsl.de |
| User-Agent | Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.17) Gecko/20110516 Lightning/1.0b2.102ipre2 Thunderbird/3.1.10 |
| In-Reply-To | <433563dc-b5bb-42f1-9023-3ec799d25505@k13g2000vbv.googlegroups.com> |
| X-Enigmail-Version | 1.1.2 |
| OpenPGP | id=AD16AB1B; url=http://cheimes.de/heimes.asc |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.12 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.694.1309944934.1164.python-list@python.org> (permalink) |
| Lines | 46 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1309944935 news.xs4all.nl 21771 [2001:888:2000:d::a6]:49461 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.python:8923 |
Show key headers only | View raw
Am 06.07.2011 11:02, schrieb Gnarlodious:
> Using introspection, is there a way to get a list of "property
> getters"?
>
> Does this:
>
> vars=property(getVars(), "Dump a string of variables and values")
>
> have some parsable feature that makes it different from other
> functions? Or would I need to use some naming scheme to parse them
> out?
dir() won't help you much here. The inspect module has several tools to
make inspection easier.
>>> import inspect
>>> class Example(object):
... @property
... def method(self):
... return 1
...
>>> inspect.getmembers(Example, inspect.isdatadescriptor)
[('__weakref__', <attribute '__weakref__' of 'Example' objects>),
('method', <property object at 0xec0520>)]
inspect.getmembers() with isdatadescriptor predicate works only on
classes, not on instances.
>>> inspect.getmembers(Example(), inspect.isdatadescriptor)
[]
Property instances have the attributes fget, fset and fdel that refer to
their getter, setter and delete method.
>>> for name, obj in inspect.getmembers(Example, inspect.isdatadescriptor):
... if isinstance(obj, property):
... print name, obj, obj.fget
...
method <property object at 0xec0520> <function method at 0xec1a28>
Christian
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Extracting property getters from dir() results Gnarlodious <gnarlodious@gmail.com> - 2011-07-06 02:02 -0700
Re: Extracting property getters from dir() results Christian Heimes <lists@cheimes.de> - 2011-07-06 11:35 +0200
Re: Extracting property getters from dir() results Gnarlodious <gnarlodious@gmail.com> - 2011-07-06 07:51 -0700
csiph-web