How best to write this try/except block?
David Bolen
db3l at fitlinxx.com
Wed Apr 3 16:14:48 EST 2002
Rich Harkins <rich at worldsinfinite.com> writes:
> Because of the is comparison even if "MYBLANKVALUE" is in d then this code
> will still work. Just don't intern whatever "MYBLANKVALUE" is (I frequently
> use undefined="UNDEFINED").
Of course, that's getting interned automatically anyway:
>>> undefined="UNDEFINED"
>>> foo="UNDEFINED"
>>> id(undefined),id(foo)
(8357472, 8357472)
>>> foo is undefined
1
You could play games (adding a space, or using a non-identifier
character) but then you're coding to a specific implementation and
optimization which could change at any time.
If you need to go this approach (wouldn't be my first choice), you
could at least use a mutable object (say []) which would be safest and
known to be unique.
--
-- David
--
/-----------------------------------------------------------------------\
\ David Bolen \ E-mail: db3l at fitlinxx.com /
| FitLinxx, Inc. \ Phone: (203) 708-5192 |
/ 860 Canal Street, Stamford, CT 06902 \ Fax: (203) 316-5150 \
\-----------------------------------------------------------------------/
More information about the Python-list
mailing list