Pass by reference?

Shae Erisson shapr at uab.edu
Wed May 24 19:18:36 EDT 2000


Dale Strickland-Clark wrote:
> 
> How do I pass a value by reference so the called routine can update it?
> 
> Here's an extract from a routine that uses ADO on NT to access a database.
> ADO will return the number of records deleted in the second parameter but
> it's not working like this.
> 
>     DBCon.Execute("delete from parts where path='%s' and drive='%s'" %
> (drive, path), delcnt)

That's not enough information for me to figure out what's wrong... can
you post five to ten lines of code and what you think they should do?

for every case I've ever seen, pass by reference is the norm in python.
you can explicity make a copy of a variable if you like though.

here's a quick demo using the 'is' operator:

class TestClass():
    def update(self, val):
        self.strx = val

>>> testy = TestClass()
>>> x = 4
>>> testy.update(x)
>>> x is testy.strx
1

The 'is' operator returns 1 (aka true) if the two references point to
the same thing, which means they 'is' the same thing.


I've heard that the Redneck version of Python (they read Py3K as PyKKK)
returns "ain't" for false.

I-have-the-right-to-make-fun-of-my-home-state!'ly y'rs
-- 
sHae mAtijs eRisson (sHae at wEbwitchEs.coM) gEnius fOr hIre
	Control - 9 out of 10 Freaks prefer it.



More information about the Python-list mailing list