Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #70980

Re: Pass variable by reference

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder4.news.weretis.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed4a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'python.': 0.02; 'python,': 0.02; 'example:': 0.03; 'cpython': 0.05; 'args': 0.07; 'postgresql': 0.07; 'rename': 0.07; 'arguments': 0.09; 'happens.': 0.09; 'immutable': 0.09; 'implements': 0.09; 'meaningful': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'python': 0.11; 'jan': 0.12; 'mechanism.': 0.16; 'mutable': 0.16; 'mutated': 0.16; 'pointers.': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'reedy': 0.16; 'sense,': 0.16; 'subject:variable': 0.16; 'wrote:': 0.18; 'variable': 0.18; 'trying': 0.19; '(where': 0.19; 'passing': 0.19; 'memory': 0.22; 'print': 0.22; 'header:User-Agent:1': 0.23; 'passes': 0.24; 'pointer': 0.24; 'question': 0.24; 'pass': 0.26; 'header:X -Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'extract': 0.31; 'file': 0.32; 'skip:- 30': 0.32; 'running': 0.33; 'copying': 0.34; 'objects': 0.35; 'version': 0.36; 'functions.': 0.36; 'var': 0.36; 'example,': 0.37; 'clear': 0.37; 'to:addr:python-list': 0.38; 'issue': 0.38; 'pm,': 0.38; 'delete': 0.39; 'to:addr:python.org': 0.39; 'either': 0.39; 'skip:p 20': 0.39; 'received:org': 0.40; 'how': 0.40; 'easy': 0.60; 'received:173': 0.61; 'skip:\xe2 10': 0.65; '8bit%:40': 0.68; 'as:': 0.81; 'burning': 0.84; 'received:fios.verizon.net': 0.84; 'skip:/ 30': 0.84
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Terry Reedy <tjreedy@udel.edu>
Subject Re: Pass variable by reference
Date Tue, 06 May 2014 15:16:54 -0400
References <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding quoted-printable
X-Gmane-NNTP-Posting-Host pool-173-75-254-207.phlapa.fios.verizon.net
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.5.0
In-Reply-To <235C4BFA-9770-481A-9FCF-21C3F036769C@gmail.com>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.9706.1399406113.18130.python-list@python.org> (permalink)
Lines 44
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1399406113 news.xs4all.nl 2869 [2001:888:2000:d::a6]:53224
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:70980

Show key headers only | View raw


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 | NextNext in thread | Find similar | Unroll thread


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