Assigning 'nochage' to a variable.

Terry Reedy tjreedy at udel.edu
Sun Sep 4 19:34:39 EDT 2005


"cjfrovik at gmail.com" <bittervine at gmail.com> wrote in message 
news:1125863892.634906.243680 at g47g2000cwa.googlegroups.com...
> Has anyone else felt a desire for a 'nochange' value

No.

> resembling the 'Z'-state of a electronic tri-state output?

Not familiar with that.

>
> var1 = 17
> var1 = func1()   # func1() returns 'nochange' this time
> print var1       # prints 17
>
> It would be equivalent to:
>
> var1 = 17
> var2, bool1 = func1()
> if bool1:
>   var1 = var2
> print var1       # prints 17

Simpler is

var1 = 17
var2 = func1()
if var2 is not 'nochange': var1 = var2

or
var1 = func2(var1)
with func2 conditionally returning the input instead of 'nochange'.
The default return, of course, could be something other than var1.

Conclusion: you can easily do what you want with Python as it is.

Terry J. Reedy






More information about the Python-list mailing list