By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,923 Members | 1,443 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,923 IT Pros & Developers. It's quick & easy.

Assigning 'nochage' to a variable.

P: n/a
Has anyone else felt a desire for a 'nochange' value
resembling the 'Z'-state of a electronic tri-state output?

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

BR/ CJF

Sep 4 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
cj******@gmail.com wrote:
Has anyone else felt a desire for a 'nochange' value
resembling the 'Z'-state of a electronic tri-state output?


No. but if you must, you can emulate that using properties or
__getattr__/__setattr__- of course then limited to classes, but writen
c.var1 instead of var1 where c is your container - that world work, if
the semantics you need are so commeon it really saves you effort.

class Container(object):

def __init__(self, nc):
"""
@param nc: a list or set of names that should not be
overwritten when None is assigned to them.
"""
self.nochanges = nc

def __setattr__(self, name, value):
if name in self.nochanges and value is not None:
self.__dict__[name] = value

Diez
Sep 4 '05 #2

P: n/a

"cj******@gmail.com" <bi********@gmail.com> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.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

Sep 4 '05 #3

P: n/a
Thanks for the suggestions, although I'll probably continue to use:

var1 = 17
var1 = func1(var1)
print var1

and have func1 return the input value if no change is required.
It's *almost* as nice as if there was a Nochange value available..

BR /CF

Sep 5 '05 #4

P: n/a
Oh, right.... I see you also thought of that.
(Sorry, didnt read your entire mail.)

Sep 5 '05 #5

P: n/a
On 5 Sep 2005 02:19:05 -0700, "cj******@gmail.com" <bi********@gmail.com> wrote:
Thanks for the suggestions, although I'll probably continue to use:

var1 = 17
var1 = func1(var1)
print var1

and have func1 return the input value if no change is required.
It's *almost* as nice as if there was a Nochange value available..

BR /CF

This seems to me a tiny snippet from a larger context, like maybe
simulating tranfer of info between circuits attached to a bus.
Posting tiny excerpts can only get you help with that, which in
the larger context might be fine or not, but no one can say ;-)

Regards,
Bengt Richter
Sep 5 '05 #6

P: n/a
On Sunday 04 September 2005 06:34 pm, Terry Reedy wrote:
resembling the 'Z'-state of a electronic tri-state output?


Not familiar with that.


"Tri-state" logic gate outputs can do one of three things:

1) They can drive the voltage to 0.0 "0"
2) They can drive the voltage to VCC "1"
3) They can act like they aren't connected at all "Z"

The "Z" actually is the standard symbol for "impedence" (in
DC circuits this is just a fancy way to say "resistance"), and
is short for "high-Z state" or "high impedence state", which
is very much like what would happen if you just cut the wire.

Sending gates into the Z state is what allows computer buses
to work at all -- only the addressed register is allowed to
control the bus wires, all other connected devices are in the
Z state.

The software equivalent is throwing certain terms out of
a sum. We usually do that with control flow. Doing it
implicitly by value seems like it could be dangerous, but
I'd have to see a more complete implementation example to
be convinced one way or the other about that.

Cheers,
Terry

--
Terry Hancock ( hancock at anansispaceworks.com )
Anansi Spaceworks http://www.anansispaceworks.com

Sep 7 '05 #7

P: n/a
On Wed, 7 Sep 2005 08:50:00 -0500, Terry Hancock
<ha*****@anansispaceworks.com> declaimed the following in
comp.lang.python:

Sending gates into the Z state is what allows computer buses
to work at all -- only the addressed register is allowed to
control the bus wires, all other connected devices are in the
Z state.
My old digital electronics class could argue that "work at all"...
TTL chips with "open collector" outputs weren't "tri-state" in the sense
used here. These used external resistors to pull the line state to High
/except/ when one of the attached devices deliberately drove it low.

Tri-state, to me, implies a circuit that can be driven to either
high or low, but when undriven floats in the dead zone (for CMOS, low is
<30% of VCC, high is >70% of VCC, 30-70% is "unset") and doesn't load
down other connected devices -- though I will concede the key item is
that the third state is that the device does not drive the signal line
in either direction.

In the present discussion however... I think I'd agree with your
comments (snipped)... This "third state" is not a special value, but
rather the absence of any value (technically, this would also mean the
absence of "None" as a return) -- and the only reasonable way to produce
such an effect in code is to use conditional logic to detect the
condition and handle it as needed.
-- ================================================== ============ <
wl*****@ix.netcom.com | Wulfraed Dennis Lee Bieber KD6MOG <
wu******@dm.net | Bestiaria Support Staff <
================================================== ============ <
Home Page: <http://www.dm.net/~wulfraed/> <
Overflow Page: <http://wlfraed.home.netcom.com/> <

Sep 7 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.