Re: unbinding a global variable in Python

2009-04-30 Thread Peter Otten
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" #

Re: unbinding a global variable in Python

2009-04-30 Thread Hrvoje Niksic
Mark Tarver writes: >> (setq *g* 0) > 0 > >> (boundp '*g*) > t 'foo' in globals() -- http://mail.python.org/mailman/listinfo/python-list

Re: unbinding a global variable in Python

2009-04-30 Thread Duncan Booth
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

Re: unbinding a global variable in Python

2009-04-30 Thread Mark Tarver
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 > >

Re: unbinding a global variable in Python

2009-04-30 Thread Diez B. Roggisch
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

unbinding a global variable in Python

2009-04-30 Thread Mark Tarver
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