Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
comp.lang.python
RE: Check For SELF Variable Existance
Robert Rawlins - Think Blue
3/11/2008 1:41:00 PM
Thank you Simon,
I was hoping there would be something as simple as that :-)
Rob
-----Original Message-----
From: python-list-bounces+robert.rawlins=thinkbluemedia.co.uk@python.org
[mailto:python-list-bounces+robert.rawlins=thinkbluemedia.co.uk@python.org]
On Behalf Of Simon Brunning
Sent: 11 March 2008 13:21
To: python-list@python.org
Subject: Re: Check For SELF Variable Existance
On Tue, Mar 11, 2008 at 11:00 AM, Robert Rawlins
<robert.rawlins@thinkbluemedia.co.uk> wrote:
> I want to be able to check if a class has a certain property in its 'self'
> scope, what's the best way to do this?
>>> class Spam(object):
.... def egg(self):
.... if hasattr(self, 'chips'): print 'got chips!'
....
>>> spam = Spam()
>>> spam.egg()
>>> spam.chips = 'beans'
>>> spam.egg()
got chips!
--
Cheers,
Simon B.
simon@brunningonline.net
http://www.brunningonline.net/s...
--
http://mail.python.org/mailman/listinfo/p...
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
RE: Check For SELF Variable Existance
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password