Why is error message value "disappearing"?

Robert Oschler no_replies at fake_email_address.invalid
Tue Jun 10 00:23:35 CEST 2003


I have code that acts as the following (stripped down for purposes of
brevity)

# errlost.py ------------------------

def errtest(errMsg):
    errMsg = "no error."
    valid_call = 0
    try:
        fldname = "test"
        # do something that raises a LookupError exception.
    except LookupError, e:
        errMsg = "Warning, lookup error occurred accessing field name <%s>"
% fldname
        print "In errtest, errMsg = ", errMsg
    return valid_call

# END: errtest

# test errtest()
errMsg = ""
if not errtest(errMsg):
        print "Outside errtest, errMsg = ", errMsg

# ====================

When I run the code I get the following printout:

    In errtest, errMsg = "Warning, lookup error occurred accessing field
name <test>"
    Outside errtest, errMsg = ""

It's as if errMsg is being passed by value and the assignment that occurs
inside errtest() doesn't "stick".  I thought Python was pass by reference?

What am I doing wrong?

thx

--
Robert Oschler,
Android Technologies, Inc.
http://www.androidtechnologies.com
- The home of Off-Book! (tm)
The scene memorization tool for Actors and Actresses!






More information about the Python-list mailing list