Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #6522
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!feeder.erje.net!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <wolfgang@rohdewald.de> |
| 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.01; 'parameter': 0.05; 'pointer': 0.05; 'received:localnet': 0.07; 'python': 0.08; 'object.': 0.09; 'parameter.': 0.09; 'subject:parameters': 0.09; 'ugly': 0.09; 'def': 0.12; 'wrote:': 0.14; 'from:addr:rohdewald.de': 0.16; 'from:addr:wolfgang': 0.16; 'from:name:wolfgang rohdewald': 0.16; 'local.': 0.16; 'message- id:@rohdewald.de': 0.16; 'received:91.62': 0.16; 'reply- to:addr:rohdewald.de': 0.16; 'reply-to:addr:wolfgang': 0.16; 'subject:function': 0.16; 'wolfgang': 0.16; 'header:In-Reply- To:1': 0.21; 'variable': 0.21; 'seems': 0.21; 'cc:2**0': 0.22; 'once.': 0.23; "doesn't": 0.25; 'function': 0.25; 'object': 0.26; 'pass': 0.27; '(the': 0.28; 'variables': 0.29; 'received:mo-p00-ob.rzone.de': 0.30; 'it.': 0.31; 'to:addr:python- list': 0.33; 'list': 0.33; 'actually': 0.33; 'list.': 0.33; 'there': 0.35; 'header:User-Agent:1': 0.35; 'function.': 0.35; 'reference': 0.35; 'considered': 0.36; 'hold': 0.36; 'charset:us- ascii': 0.36; 'references': 0.37; 'think': 0.38; 'could': 0.38; 'but': 0.38; 'subject:: ': 0.38; 'called': 0.39; 'unless': 0.39; 'itself.': 0.39; 'either': 0.39; 'to:addr:python.org': 0.39; 'more': 0.60; 'within': 0.60; 'header:Message-Id:1': 0.62; 'header :Reply-To:1': 0.72; 'reply-to:no real name:2**0': 0.72 |
| DKIM-Signature | v=1; a=rsa-sha1; c=relaxed/relaxed; t=1306662444; l=949; s=domk; d=rohdewald.de; h=Content-Transfer-Encoding:Content-Type:MIME-Version:In-Reply-To: References:Cc:Date:Subject:To:Reply-To:From:X-RZG-CLASS-ID:X-RZG-AUTH; bh=YHbHzW6rEi2X3DTl2JoPyZ5e2xo=; b=rt/F+z2c/hyuHWvcssps/DY4oIw+QWf5X06Cz6MEwW4x/ldzr8t+OFbzBpZdY8OFySZ Z00KT6RFFBOJ+zlmdtLvf1MTB8BF9ceH/qN5eeLj/pi7BAnVsvOJ/meXfrtYMigcsa/5r fAfPu2nIipIoKHD7oxrCMak+mJirJ7HPr+w= |
| X-RZG-AUTH | :O2MIc0epdfgAjoV+frHI3UhxNCLBO5P+YS73lHhJYRD2uAuzaM+5N8MTpurqLXil |
| X-RZG-CLASS-ID | mo00 |
| From | Wolfgang Rohdewald <wolfgang@rohdewald.de> |
| To | python-list@python.org |
| Subject | Re: scope of function parameters |
| Date | Sun, 29 May 2011 11:47:26 +0200 |
| User-Agent | KMail/1.13.6 (Linux/2.6.38-8-generic; KDE/4.6.3; x86_64; ; ) |
| References | <F8395F78-615E-4FBD-B6FC-1D6173EAEA45@mcgill.ca> |
| In-Reply-To | <F8395F78-615E-4FBD-B6FC-1D6173EAEA45@mcgill.ca> |
| MIME-Version | 1.0 |
| Content-Type | Text/Plain; charset="us-ascii" |
| Content-Transfer-Encoding | 7bit |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.12 |
| Precedence | list |
| Reply-To | wolfgang@rohdewald.de |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://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 | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.2217.1306662671.9059.python-list@python.org> (permalink) |
| Lines | 32 |
| NNTP-Posting-Host | 82.94.164.166 |
| X-Trace | 1306662671 news.xs4all.nl 49178 [::ffff:82.94.164.166]:38804 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.python:6522 |
Show key headers only | View raw
On Sonntag 29 Mai 2011, Henry Olders wrote:
> It seems that in Python, a variable inside a function is
> global unless it's assigned.
no, they are local
> I would have thought that a function parameter would
> automatically be considered local to the function. It doesn't
> make sense to me to pass a global to a function as a
> parameter.
it is local. But consider what you actually passed:
You did not pass a copy of the list but the list itself.
You could also say you passed a reference to the list.
All python variables only hold a pointer (the id) to
an object. This object has a reference count and is
automatically deleted when there are no more references
to it.
If you want a local copy of the list you can either
do what you called being ugly or do just that within
the function itself - which I think is cleaner and
only required once.
def fnc2(c):
c = c[:]
c[1] = 'having'
return c
--
Wolfgang
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll thread
Re: scope of function parameters Wolfgang Rohdewald <wolfgang@rohdewald.de> - 2011-05-29 11:47 +0200
Re: scope of function parameters Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-05-29 12:47 +0000
Re: scope of function parameters Chris Angelico <rosuav@gmail.com> - 2011-05-30 03:53 +1000
Re: scope of function parameters Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-05-29 18:28 +0000
Re: scope of function parameters Chris Rebert <clp2@rebertia.com> - 2011-05-29 11:01 -0700
Re: scope of function parameters Chris Angelico <rosuav@gmail.com> - 2011-05-30 04:38 +1000
Re: scope of function parameters Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-05-29 18:53 +0000
Re: scope of function parameters Chris Angelico <rosuav@gmail.com> - 2011-05-30 05:20 +1000
Re: scope of function parameters Ian Kelly <ian.g.kelly@gmail.com> - 2011-05-29 13:12 -0600
csiph-web