Passing arguments by value...

Curtis Jensen cjensen at be-research.ucsd.edu
Fri Feb 25 18:16:21 EST 2000


Arrays in Numeric are pass by reference (mutable objects).  Sometimes
it's possible to trick Python by declaring something as an array of size
one.  Though it probably won't work in this case.  Also, it's a hack and
not good code, but sometimes you can't argue with what works.

--
Curtis

John Zelle wrote:
> 
> Actually, parameters _are_ passed by value in Python.  However, as you
> discovered, variables are actually just references to objects.
> Technically, the reference is being passed by value.
> 
> Probably the solution to your problem is to copy the object.  Check out
> the copy module.
> 
> John Zelle
> zelle at wartburg.edu
> 
> "John F. Brainard" wrote:
> >
> > I'm working on a set of HTML Layout classes for CGI programming
> > in Python and have stumbled upon a small problem...
> >
> > The sample code below should be self explanitory...
> >
> > #begin python code
> > html = body.Body()
> >
> > font1 = tags.Font(4, "Arial", "#FF0000")
> > font1.addText(string.strip("""
> >         Some text would go in here.
> > """))
> >
> > html.addElement(font)
> >
> > font1.clearText()
> > font1.addText(string.strip("""
> >         Some other text here.
> > """))
> >
> > print "<HTML>" + str(html) + "</HTML>"
> > #end python code
> >
> > After I create the font1 object and set it's properties, I add it
> > to the html object. Then, I change the text and add it again to
> > the html object. What I get as the output is...
> >
> > #Begin HTML here
> > <HTML>
> > <body>
> > <font size=1 face="Arial" color="#FF0000">
> > Some other text here.
> > </font>
> >
> > <font size=1 face="Arial" color="#FF0000">
> > Some other text here.
> > </font>
> > </HTML>
> > #End HTML here
> >
> > Is there a way to copy the font object or pass it by value rather
> > than reference to the addElement() function?
> >
> > Thank you,
> >
> > John F. Brainard Jr.
> > johnbrainard at stny.rr.com



More information about the Python-list mailing list