Mark Tarver wrote:
> In Lisp this is done so
>
>> (setq *g* 0)
> 0
>
>> *g*
> 0
>
>> (makunbound '*g*)
> *g*
>
>> *g*
> error: unbound variable
>
> How is this done in Python?
Often it is a better choice to initialize the global with a sentinel:
g = None
# ...
g = "something meaningful"
#
Mark Tarver writes:
>> (setq *g* 0)
> 0
>
>> (boundp '*g*)
> t
'foo' in globals()
--
http://mail.python.org/mailman/listinfo/python-list
Mark Tarver wrote:
> Great; and how can I test to see if a global is bound?
>
> e.g Lisp
>
>> (setq *g* 0)
> 0
>
>> (boundp '*g*)
> t
By trying to access it and catching the NameError exception if it isn't
defined.
--
Duncan Booth http://kupuguy.blogspot.com
--
http://mail.python.org/mail
On 30 Apr, 12:36, "Diez B. Roggisch" wrote:
> Mark Tarver wrote:
> > In Lisp this is done so
>
> >> (setq *g* 0)
> > 0
>
> >> *g*
> > 0
>
> >> (makunbound '*g*)
> > *g*
>
> >> *g*
> > error: unbound variable
>
> > How is this done in Python?
>
> > Mark
> >>> foo = "bar"
> >>> del foo
> >>> foo
>
>
Mark Tarver wrote:
> In Lisp this is done so
>
>> (setq *g* 0)
> 0
>
>> *g*
> 0
>
>> (makunbound '*g*)
> *g*
>
>> *g*
> error: unbound variable
>
> How is this done in Python?
>
> Mark
>>> foo = "bar"
>>> del foo
>>> foo
Traceback (most recent call last):
File "", line 1, in
NameError: n
In Lisp this is done so
> (setq *g* 0)
0
> *g*
0
> (makunbound '*g*)
*g*
> *g*
error: unbound variable
How is this done in Python?
Mark
--
http://mail.python.org/mailman/listinfo/python-list