[sage-support] Re: Change to a local variable affects the variable outside the program

2008-12-16 Thread Robert Bradshaw
On Dec 15, 2008, at 12:53 PM, Simon King wrote: > Dear Lars, dear Robert, > >> The explanation is hidden in a footnote in the tutorial. Please see >> "Defining Functions" in "More Control Flow Tools" in the Python >> Tutorial:http://docs.python.org/tutorial/controlflow.html#defining- >> function

[sage-support] Re: Change to a local variable affects the variable outside the program

2008-12-15 Thread Simon King
Dear Lars, dear Robert, > The explanation is hidden in a footnote in the tutorial. Please see > "Defining Functions" in "More Control Flow Tools" in the Python > Tutorial:http://docs.python.org/tutorial/controlflow.html#defining-functions That part of the documentation seems misleading to me and

[sage-support] Re: Change to a local variable affects the variable outside the program

2008-12-15 Thread Robert Bradshaw
On Dec 14, 2008, at 4:05 AM, Lars Fischer wrote: > Hello Giovanni, > > you have hit one of my favorite Python Pitfalls: Python does always > call by value, but sometimes it behaves like call by reference . Correction, Python *always* does call by reference. Fortunately, most basic types (ints,

[sage-support] Re: Change to a local variable affects the variable outside the program

2008-12-14 Thread Lars Fischer
Hello Giovanni, most of the time it does "the right thing". If you really need call by value, whatever type the argument is, you can (must) copy the argument yourself. The copy module provides the methods copy.copy() and copy.deepcopy() for this situation. With best regards, Lars --~--~

[sage-support] Re: Change to a local variable affects the variable outside the program

2008-12-14 Thread giovanni.marche...@ds.unifi.it
Thank you Lars, I had the feeling that this behavior should be something related to Python, but I was impressed by the inconsistency, because in my first example everything worked as (I) intended. So, if this is a feature of Python I have to study it carefully ! Best regards Giovanni On Dec

[sage-support] Re: Change to a local variable affects the variable outside the program

2008-12-14 Thread Lars Fischer
Hello Giovanni, you have hit one of my favorite Python Pitfalls: Python does always call by value, but sometimes it behaves like call by reference . The explanation is hidden in a footnote in the tutorial. Please see "Defining Functions" in "More Control Flow Tools" in the Python Tutorial: http: