Hello Guys,
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? I've seen a few examples of people
using a try: block to test if the variable exists but to be honest, this
seems a little bit verbose, do we not have a better method
On Tue, Mar 11, 2008 at 11:00 AM, Robert Rawlins
[EMAIL PROTECTED] 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!'
...
Thank you Simon,
I was hoping there would be something as simple as that :-)
Rob
-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]
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
Robert Rawlins [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
| Thank you Simon,
|
| I was hoping there would be something as simple as that :-)
| class Spam(object):
| ... def egg(self):
| ... if hasattr(self, 'chips'): print 'got chips!'
I strongly suggest that you