Pass variable by reference

Michael Torrie torriem at gmail.com
Tue May 6 16:57:12 EDT 2014


On 05/05/2014 06:39 PM, Satish Muthali wrote:
> I want to nuke /var/lib/postgresql/9.3.4/main/data , however
> programatically I want it to be as:  /var/lib/postgresql/<value of
> pgversion>/main/data
> 
> Any help is appreciated.

Not sure really.  But if you want to pass a some data around that can be
manipulated "in place" as it were, say in a function, then yes it must
be either a mutable object like a list or a dictionary, or you can wrap
up your data in a class and manipulate it via an instance of that class
that you pass around.  You can do the same thing in a module too,
actually, which is a form of singleton.

Another solution is just to have a function return a new cooked string,
based on a raw string passed in as a parameter.

Perhaps if you explained more clearly your end goal, people could
suggest ideas in accomplishing it in a way that works well in Python.



More information about the Python-list mailing list