Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #70980
| From | Terry Reedy <tjreedy@udel.edu> |
|---|---|
| Subject | Re: Pass variable by reference |
| Date | 2014-05-06 15:16 -0400 |
| References | <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.9706.1399406113.18130.python-list@python.org> (permalink) |
On 5/5/2014 8:39 PM, Satish Muthali wrote:
> Hello experts,
>
> I have a burning question on how to pass variable by reference in
> Python.
Python passes objects to functions. CPython implements this by passing
object pointers. In one sense, your request is impossible. In another,
it already happens.
> I understand that the data type has to be mutable.
In C, all data are mutable, so copying a block of memory versus passing
a pointer is the meaningful distinction. In Python, mutable arguments
can be mutated and immutable args cannot, so *that* is the only
meaningful distinction. Strings are not mutable.
> For example, here’s the issue I am running in to:
>
> I am trying to extract the PostgreSQL DB version for example:
>
> /pgVer = [s.split() for s in os.popen("psql
> --version").read().splitlines()]/
> / print pgVer[0]/
> / for i, var in enumerate(pgVer[0]):/
> / if i == len(pgVer[0]) - 1:/
> / pgversion = var/
> /
> /
> I would now like to pass ‘pgversion’ (where the value of pgversion is
> 9.3.4) by reference, for example:
>
> 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
It is not clear whether you want to delete a file or rename it. Either
is easy and neither depend on passing mechanism.
--
Terry Jan Reedy
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll thread
Re: Pass variable by reference Terry Reedy <tjreedy@udel.edu> - 2014-05-06 15:16 -0400 Re: Pass variable by reference Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-05-07 01:18 +0000
csiph-web