Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #26860
| Path | csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <d@davea.name> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.001 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'subject:: [': 0.03; 'value,': 0.03; 'caller': 0.07; 'function,': 0.07; 'subject:question': 0.08; 'assigning': 0.09; 'global,': 0.09; 'parameter.': 0.09; 'cc:addr:python-list': 0.10; 'def': 0.10; 'value.': 0.15; '"right"': 0.16; '12:07,': 0.16; 'not;': 0.16; 'top-level': 0.16; 'string': 0.17; 'wrote:': 0.17; 'code,': 0.18; 'subject:] ': 0.19; 'modifying': 0.22; 'of.': 0.22; 'cc:2**0': 0.23; 'cc:no real name:2**0': 0.24; 'second': 0.24; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'header :User-Agent:1': 0.26; 'am,': 0.27; 'correct': 0.28; 'modified,': 0.29; 'case,': 0.29; 'structure': 0.32; 'subject:lists': 0.32; 'point,': 0.33; 'third': 0.34; 'returning': 0.35; 'there': 0.35; 'level.': 0.36; 'level': 0.37; 'rather': 0.37; 'object': 0.38; 'some': 0.38; 'received:192': 0.39; 'called': 0.39; 'received:192.168': 0.40; 'think': 0.40; 'more': 0.63; 'managing': 0.64; 'taking': 0.65; 'header:Reply-To:1': 0.68; 'received:74.208': 0.71; 'reply-to:no real name:2**0': 0.72; 'as:': 0.75; 'received:74.208.4.194': 0.84 |
| Date | Fri, 10 Aug 2012 06:53:19 -0400 |
| From | Dave Angel <d@davea.name> |
| User-Agent | Mozilla/5.0 (X11; Linux x86_64; rv:14.0) Gecko/20120714 Thunderbird/14.0 |
| MIME-Version | 1.0 |
| To | Mok-Kong Shen <mok-kong.shen@t-online.de> |
| Subject | Re: [newbie] A question about lists and strings |
| References | <k02jn0$id2$1@news.albasani.net> <mailman.3150.1344593295.4697.python-list@python.org> <k02nt5$r8p$1@news.albasani.net> |
| In-Reply-To | <k02nt5$r8p$1@news.albasani.net> |
| Content-Type | text/plain; charset=ISO-8859-1 |
| Content-Transfer-Encoding | 7bit |
| X-Provags-ID | V02:K0:qXng+9kUuJ5+s/nRXk/OfVEm5AkycgK6veAhZOW/0sH Elwjcdq4SYCG1VJe6JPyJiOBXlabk7+MEUEQeswER3jk1mu1N8 yNRFe/FN2cKipUMUViKfaL6REaGcZtmJphyejzixmellfNglxQ tfSwTr0kv6oKnrLYnA9EaGq6YjJxCHHeSdkN3M96Zj+3zn8FXg nOodgsOceWBkq953VVFzTpabg1e9lAZhR/K9030HwmmbMh8jPa w8RY2dhfwOYo/r8wTb3nW16lfmNA148vAsX20YOnxAKFcxFA3A ULmeB2b1r75cJI76BAFc09LE4791982tS0x4x7bHQriWurz9A= = |
| Cc | python-list@python.org |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.12 |
| Precedence | list |
| Reply-To | d@davea.name |
| 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.3154.1344596023.4697.python-list@python.org> (permalink) |
| Lines | 40 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1344596023 news.xs4all.nl 6983 [2001:888:2000:d::a6]:40959 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:26860 |
Show key headers only | View raw
On 08/10/2012 06:31 AM, Mok-Kong Shen wrote:
> Am 10.08.2012 12:07, schrieb Dave Angel:
> [snip]
>> At this point, in top-level code, the listb object has been modified,
>> and the strb one has not; it still is bound to the old value.
>
> This means there is no way of modifying a string at the top level
> via a function, excepting through returning a new value and assigning
> that to the string name at the top level. Please again correct me, if
> I am wrong.
>
> M. K. Shen
>
You're close. There are three ways I can think of. The "right" way is
to return a value, which the caller can use any way he wants, including
binding it to a global.
Second is to declare the name as global, rather than taking the object
as a formal parameter. In this case, you're taking on the
responsibility for managing that particular global, by its correct name.
def yy():
global strb
strb += "whatever"
Third is to hold the string in some more complex structure which is
mutable. (untested, may contain typos)
def zz(mydict):
mydict["key1"] += "text"
called as:
globaldict = {"key1": "initial ", "key2": "init"}
--
DaveA
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread
[newbie] A question about lists and strings Mok-Kong Shen <mok-kong.shen@t-online.de> - 2012-08-10 11:19 +0200
Re: [newbie] A question about lists and strings Roman Vashkevich <vashkevichrb@gmail.com> - 2012-08-10 13:28 +0400
Re: [newbie] A question about lists and strings Roman Vashkevich <vashkevichrb@gmail.com> - 2012-08-10 13:48 +0400
Re: [newbie] A question about lists and strings Mok-Kong Shen <mok-kong.shen@t-online.de> - 2012-08-10 12:12 +0200
Re: [newbie] A question about lists and strings Chris Angelico <rosuav@gmail.com> - 2012-08-10 20:37 +1000
Re: [newbie] A question about lists and strings Dave Angel <d@davea.name> - 2012-08-10 06:37 -0400
Re: [newbie] A question about lists and strings Roman Vashkevich <vashkevichrb@gmail.com> - 2012-08-10 14:56 +0400
Re: [newbie] A question about lists and strings Mok-Kong Shen <mok-kong.shen@t-online.de> - 2012-08-10 13:08 +0200
Re: [newbie] A question about lists and strings Dave Angel <d@davea.name> - 2012-08-10 06:56 -0400
Re: [newbie] A question about lists and strings Chris Angelico <rosuav@gmail.com> - 2012-08-10 21:00 +1000
Re: [newbie] A question about lists and strings Roman Vashkevich <vashkevichrb@gmail.com> - 2012-08-10 15:06 +0400
Re: [newbie] A question about lists and strings Peter Otten <__peter__@web.de> - 2012-08-10 11:59 +0200
Re: [newbie] A question about lists and strings Rotwang <sg552@hotmail.co.uk> - 2012-08-10 16:12 +0100
Re: [newbie] A question about lists and strings Dave Angel <d@davea.name> - 2012-08-10 06:07 -0400
Re: [newbie] A question about lists and strings Mok-Kong Shen <mok-kong.shen@t-online.de> - 2012-08-10 12:31 +0200
Re: [newbie] A question about lists and strings Chris Angelico <rosuav@gmail.com> - 2012-08-10 20:40 +1000
Re: [newbie] A question about lists and strings Mok-Kong Shen <mok-kong.shen@t-online.de> - 2012-08-10 12:48 +0200
Re: [newbie] A question about lists and strings Dave Angel <d@davea.name> - 2012-08-10 06:58 -0400
Re: [newbie] A question about lists and strings Dave Angel <d@davea.name> - 2012-08-10 06:53 -0400
csiph-web