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


Groups > comp.lang.python > #29963 > unrolled thread

which a is used?

Started byJayden <jayden.shui@gmail.com>
First post2012-09-24 16:43 -0700
Last post2012-09-25 11:30 +0200
Articles 15 on this page of 35 — 15 participants

Back to article view | Back to comp.lang.python


Contents

  which a is used? Jayden <jayden.shui@gmail.com> - 2012-09-24 16:43 -0700
    Re: which a is used? Dwight Hutto <dwightdhutto@gmail.com> - 2012-09-24 19:57 -0400
    Re: which a is used? Dwight Hutto <dwightdhutto@gmail.com> - 2012-09-24 20:06 -0400
    Re: which a is used? alex23 <wuwei23@gmail.com> - 2012-09-24 17:08 -0700
      Re: which a is used? Dwight Hutto <dwightdhutto@gmail.com> - 2012-09-24 21:13 -0400
        Re: which a is used? alex23 <wuwei23@gmail.com> - 2012-09-24 19:14 -0700
          Re: which a is used? Dwight Hutto <dwightdhutto@gmail.com> - 2012-09-24 22:37 -0400
            Re: which a is used? Thomas Rachel <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de> - 2012-09-25 07:07 +0200
              Re: which a is used? Dwight Hutto <dwightdhutto@gmail.com> - 2012-09-25 01:30 -0400
                Re: which a is used? alex23 <wuwei23@gmail.com> - 2012-09-25 05:48 -0700
              Re: which a is used? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2012-09-25 08:44 +0100
              Stop feeding the trolls (Was: which a is used?) D'Arcy Cain <darcy@druid.net> - 2012-09-25 09:53 -0400
              Re: Stop feeding the trolls (Was: which a is used?) David Robinow <drobinow@gmail.com> - 2012-09-25 21:00 -0400
              Re: Stop feeding the trolls (Was: which a is used?) Dwight Hutto <dwightdhutto@gmail.com> - 2012-09-26 03:06 -0400
                Re: Stop feeding the trolls (Was: which a is used?) alex23 <wuwei23@gmail.com> - 2012-09-26 17:40 -0700
                  Re: Stop feeding the trolls Ben Finney <ben+python@benfinney.id.au> - 2012-09-27 13:06 +1000
                  Re: Stop feeding the trolls Dwight Hutto <dwightdhutto@gmail.com> - 2012-09-27 23:39 -0400
                  Re: Stop feeding the trolls (Was: which a is used?) Dwight Hutto <dwightdhutto@gmail.com> - 2012-09-27 23:47 -0400
                  Re: Stop feeding the trolls (Was: which a is used?) Chris Angelico <rosuav@gmail.com> - 2012-09-28 14:40 +1000
                  Re: Stop feeding the trolls (Was: which a is used?) Dwight Hutto <dwightdhutto@gmail.com> - 2012-09-28 00:50 -0400
                  Re: Stop feeding the trolls (Was: which a is used?) "Littlefield, Tyler" <tyler@tysdomain.com> - 2012-09-27 23:12 -0600
                  Re: Stop feeding the trolls (Was: which a is used?) Dwight Hutto <dwightdhutto@gmail.com> - 2012-09-28 01:21 -0400
                    Re: Stop feeding the trolls (Was: which a is used?) rusi <rustompmody@gmail.com> - 2012-09-27 22:51 -0700
                      Re: Stop feeding the trolls (Was: which a is used?) Dwight Hutto <dwightdhutto@gmail.com> - 2012-09-28 02:20 -0400
              Re: Stop feeding the trolls (Was: which a is used?) Dwight Hutto <dwightdhutto@gmail.com> - 2012-09-26 03:07 -0400
          Re: which a is used? "Colin J. Williams" <cjw@ncf.ca> - 2012-09-25 08:52 -0400
        Re: which a is used? Thomas Rachel <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de> - 2012-09-25 07:06 +0200
          Re: which a is used? Dwight Hutto <dwightdhutto@gmail.com> - 2012-09-25 01:22 -0400
            Re: which a is used? Thomas Rachel <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de> - 2012-09-25 07:39 +0200
      Re: which a is used? Terry Reedy <tjreedy@udel.edu> - 2012-09-25 01:05 -0400
    Re: which a is used? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-09-25 01:18 +0000
      Re: which a is used? Dwight Hutto <dwightdhutto@gmail.com> - 2012-09-24 21:47 -0400
        Re: which a is used? Thomas Rachel <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de> - 2012-09-25 07:06 +0200
      Re: which a is used? Dwight Hutto <dwightdhutto@gmail.com> - 2012-09-24 21:50 -0400
    Re: which a is used? Alain Ketterlin <alain@dpt-info.u-strasbg.fr> - 2012-09-25 11:30 +0200

Page 2 of 2 — ← Prev page 1 [2]


#30358 — Re: Stop feeding the trolls (Was: which a is used?)

From"Littlefield, Tyler" <tyler@tysdomain.com>
Date2012-09-27 23:12 -0600
SubjectRe: Stop feeding the trolls (Was: which a is used?)
Message-ID<mailman.1536.1348809188.27098.python-list@python.org>
In reply to#30258
On 9/27/2012 10:50 PM, Dwight Hutto wrote:
> On Fri, Sep 28, 2012 at 12:40 AM, Chris Angelico <rosuav@gmail.com> wrote:
>> On Fri, Sep 28, 2012 at 1:47 PM, Dwight Hutto <dwightdhutto@gmail.com> wrote:
>>> [ lots of screed that demonstrates that Dwight hasn't grokked the hacker culture ]
> Don't hack, but could very well if necessary.

You couldn't hack your self out of a wet paper bag, and you're fooling noone. Sorry... buddy. You should go away now; You asked who is laughing at you the other day, and at that point you had the ability to salvage (or at least attempt to salvage) your reputation with a few people. You've pretty much blown that away at this point, so a belated answer to your question is everyone.

>> Dwight, have a read of these documents. They may help you to
>> understand how the python-list community operates, and perhaps more
>> so, why most of the regulars here think the way they do.
> They have double digit I.Q.'s ?
>
> Actually,
>> this may be of interest to quite a few people, so I'll post it
>> on-list.
> Go right ahead....buddy.
>
>> http://catb.org/~esr/faqs/
>>
>> ChrisA
>> --
>> http://mail.python.org/mailman/listinfo/python-list
>
>


-- 
Take care,
Ty
http://tds-solutions.net
The aspen project: a barebones light-weight mud engine:
http://code.google.com/p/aspenmud
He that will not reason is a bigot; he that cannot reason is a fool; he that dares not reason is a slave.

[toc] | [prev] | [next] | [standalone]


#30359 — Re: Stop feeding the trolls (Was: which a is used?)

FromDwight Hutto <dwightdhutto@gmail.com>
Date2012-09-28 01:21 -0400
SubjectRe: Stop feeding the trolls (Was: which a is used?)
Message-ID<mailman.1538.1348809681.27098.python-list@python.org>
In reply to#30258
On Fri, Sep 28, 2012 at 1:12 AM, Littlefield, Tyler <tyler@tysdomain.com> wrote:
> On 9/27/2012 10:50 PM, Dwight Hutto wrote:
>>
>> On Fri, Sep 28, 2012 at 12:40 AM, Chris Angelico <rosuav@gmail.com> wrote:
>>>
>>> On Fri, Sep 28, 2012 at 1:47 PM, Dwight Hutto <dwightdhutto@gmail.com>
>>> wrote:
>>>>
>>>> [ lots of screed that demonstrates that Dwight hasn't grokked the hacker
>>>> culture ]
>>
>> Don't hack, but could very well if necessary.
>
>
> You couldn't hack your self out of a wet paper bag, and you're fooling
> noone.

Yeah I could.


 Sorry... buddy. You should go away now;

So you can dominate with a lame ass attempt to approach my responses
with a manipulative tactic to discredit me, including such hits as
racism, and sexism?


You asked who is laughing at
> you the other day, and at that point you had the ability to salvage (or at
> least attempt to salvage) your reputation with a few people.

Nobody, they're laughing at your failed attempt to discredit me in a
on thread response in which I was a respondent.

Please don't disguise your foolishnish with lies.


 You've pretty
> much blown that away at this point, so a belated answer to your question is
> everyone.

You mean I went to sleep, woke up and responded? Nice attempt, but you
can set a random seed of mine up your ass.

>
>
>>> Dwight, have a read of these documents. They may help you to
>>> understand how the python-list community operates, and perhaps more
>>> so, why most of the regulars here think the way they do.
>>
>> They have double digit I.Q.'s ?
>>
>> Actually,
>>>
>>> this may be of interest to quite a few people, so I'll post it
>>> on-list.
>>
>> Go right ahead....buddy.
>>
>>> http://catb.org/~esr/faqs/
>>>
>>> ChrisA
>>> --
>>> http://mail.python.org/mailman/listinfo/python-list
>>
>>
>>
>
>
> --
> Take care,
> Ty
> http://tds-solutions.net
> The aspen project: a barebones light-weight mud engine:
> http://code.google.com/p/aspenmud
> He that will not reason is a bigot; he that cannot reason is a fool; he that
> dares not reason is a slave.
>



-- 
Best Regards,
David Hutto
CEO: http://www.hitwebdevelopment.com

[toc] | [prev] | [next] | [standalone]


#30362 — Re: Stop feeding the trolls (Was: which a is used?)

Fromrusi <rustompmody@gmail.com>
Date2012-09-27 22:51 -0700
SubjectRe: Stop feeding the trolls (Was: which a is used?)
Message-ID<5b7694f7-474c-41dd-8de3-7ad1b6a96210@s9g2000pbh.googlegroups.com>
In reply to#30359
On Sep 28, 10:21 am, Dwight Hutto <dwightdhu...@gmail.com> wrote:
> On Fri, Sep 28, 2012 at 1:12 AM, Littlefield, Tyler <ty...@tysdomain.com> wrote:
> > On 9/27/2012 10:50 PM, Dwight Hutto wrote:
>
> >> On Fri, Sep 28, 2012 at 12:40 AM, Chris Angelico <ros...@gmail.com> wrote:
>
> >>> On Fri, Sep 28, 2012 at 1:47 PM, Dwight Hutto <dwightdhu...@gmail.com>
> >>> wrote:
>
> >>>> [ lots of screed that demonstrates that Dwight hasn't grokked the hacker
> >>>> culture ]
>
> >> Don't hack, but could very well if necessary.
>
> > You couldn't hack your self out of a wet paper bag, and you're fooling
> > noone.
>
> Yeah I could.
>
>  Sorry... buddy. You should go away now;
>
> So you can dominate with a lame ass attempt to approach my responses
> with a manipulative tactic to discredit me, including such hits as
> racism, and sexism?
>
> You asked who is laughing at
>
> > you the other day, and at that point you had the ability to salvage (or at
> > least attempt to salvage) your reputation with a few people.
>
> Nobody, they're laughing at your failed attempt to discredit me in a
> on thread response in which I was a respondent.
>
> Please don't disguise your foolishnish with lies.
>
>  You've pretty
>
> > much blown that away at this point, so a belated answer to your question is
> > everyone.
>
> You mean I went to sleep, woke up and responded? Nice attempt, but you
> can set a random seed of mine up your ass.
>
>
>
>
>
>
>
>
>
>
>
> >>> Dwight, have a read of these documents. They may help you to
> >>> understand how the python-list community operates, and perhaps more
> >>> so, why most of the regulars here think the way they do.
>
> >> They have double digit I.Q.'s ?
>
> >> Actually,
>
> >>> this may be of interest to quite a few people, so I'll post it
> >>> on-list.
>
> >> Go right ahead....buddy.
>
> >>>http://catb.org/~esr/faqs/
>
> >>> ChrisA
> >>> --
> >>>http://mail.python.org/mailman/listinfo/python-list
>
> > --
> > Take care,
> > Ty
> >http://tds-solutions.net
> > The aspen project: a barebones light-weight mud engine:
> >http://code.google.com/p/aspenmud
> > He that will not reason is a bigot; he that cannot reason is a fool; he that
> > dares not reason is a slave.

Some facts that are well-known enough but somehow seem relevant to
this discussion.
Technology is called a great enabler -- A little less gushingly its a
great multiplier.
When we look a little impartially at it we see that as technology
increases in scope/power the corresponding human involvement gets more
and more passive.

Coming to the specific technology-stack -- mailing-lists atop the
internet -- we see the following:
When I hit the send button Ive no idea who will read what I send.
Likewise what I end up reading may not be something I specifically
wish to read.

Specifically, Ive no idea what is the size of the python-list
readership -- surely in hundreds, more likely thousands.

So when I feel like making a response to one or two people which has
more heat than (python-related) light, it would help to consider the
thousand(s) who will read it who are not involved/interested in the
fracas.

A more physical analogy: Lets say I am driving along happily on the
freeway and someone does something to me that generates severe
justifiable road-rage. So I stop the car, get down and do my schtick
-- shout, shoot, mow-him-down, whatever -- and in the process create a
jam of a hundred vehicles all around.  However justifiable my rage, I
would be lucky to get anyone's support!

A more personal point. I find that anger is usually a thin cover for
depression. And depression inversely correlates with amount of
sunshine I see.  So before hitting the send button, it may be a good
idea to sleep over and see if the rising sun changes my mood.

Coming to threads like this one:
We've seen an old member of this list scolded for stretching the
drinking jokes a bit too far.
And another old member who posted a youtube link which had nothing to
do with python even though the subject said 'OT'

So… Staying withing python-related discussions and using courteous
language is the general rule for all. If you follow that you should be
ok

[toc] | [prev] | [next] | [standalone]


#30363 — Re: Stop feeding the trolls (Was: which a is used?)

FromDwight Hutto <dwightdhutto@gmail.com>
Date2012-09-28 02:20 -0400
SubjectRe: Stop feeding the trolls (Was: which a is used?)
Message-ID<mailman.1540.1348813214.27098.python-list@python.org>
In reply to#30362
On Fri, Sep 28, 2012 at 1:51 AM, rusi <rustompmody@gmail.com> wrote:
> On Sep 28, 10:21 am, Dwight Hutto <dwightdhu...@gmail.com> wrote:
>> On Fri, Sep 28, 2012 at 1:12 AM, Littlefield, Tyler <ty...@tysdomain.com> wrote:
>> > On 9/27/2012 10:50 PM, Dwight Hutto wrote:
>>
>> >> On Fri, Sep 28, 2012 at 12:40 AM, Chris Angelico <ros...@gmail.com> wrote:
>>
>> >>> On Fri, Sep 28, 2012 at 1:47 PM, Dwight Hutto <dwightdhu...@gmail.com>
>> >>> wrote:
>>
>> >>>> [ lots of screed that demonstrates that Dwight hasn't grokked the hacker
>> >>>> culture ]
>>
>> >> Don't hack, but could very well if necessary.
>>
>> > You couldn't hack your self out of a wet paper bag, and you're fooling
>> > noone.
>>
>> Yeah I could.
>>
>>  Sorry... buddy. You should go away now;
>>
>> So you can dominate with a lame ass attempt to approach my responses
>> with a manipulative tactic to discredit me, including such hits as
>> racism, and sexism?
>>
>> You asked who is laughing at
>>
>> > you the other day, and at that point you had the ability to salvage (or at
>> > least attempt to salvage) your reputation with a few people.
>>
>> Nobody, they're laughing at your failed attempt to discredit me in a
>> on thread response in which I was a respondent.
>>
>> Please don't disguise your foolishnish with lies.
>>
>>  You've pretty
>>
>> > much blown that away at this point, so a belated answer to your question is
>> > everyone.
>>
>> You mean I went to sleep, woke up and responded? Nice attempt, but you
>> can set a random seed of mine up your ass.
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> >>> Dwight, have a read of these documents. They may help you to
>> >>> understand how the python-list community operates, and perhaps more
>> >>> so, why most of the regulars here think the way they do.
>>
>> >> They have double digit I.Q.'s ?
>>
>> >> Actually,
>>
>> >>> this may be of interest to quite a few people, so I'll post it
>> >>> on-list.
>>
>> >> Go right ahead....buddy.
>>
>> >>>http://catb.org/~esr/faqs/
>>
>> >>> ChrisA
>> >>> --
>> >>>http://mail.python.org/mailman/listinfo/python-list
>>
>> > --
>> > Take care,
>> > Ty
>> >http://tds-solutions.net
>> > The aspen project: a barebones light-weight mud engine:
>> >http://code.google.com/p/aspenmud
>> > He that will not reason is a bigot; he that cannot reason is a fool; he that
>> > dares not reason is a slave.
>
> Some facts that are well-known enough but somehow seem relevant to
> this discussion.
> Technology is called a great enabler -- A little less gushingly its a
> great multiplier.
> When we look a little impartially at it we see that as technology
> increases in scope/power the corresponding human involvement gets more
> and more passive.
>

But technology should be engaged by many different view points, in
order to insure that the output of technology is within the, not only
the grasp of outsiders, but the scope of those who wish to debate it's
usage in many different areas in order to have stability of the
society(societies) that produce the output.

> Coming to the specific technology-stack -- mailing-lists atop the
> internet -- we see the following:
> When I hit the send button Ive no idea who will read what I send.
> Likewise what I end up reading may not be something I specifically
> wish to read.

That's common on mailing lists, and the discussions they maintain, as
well as the usage membership.



>
> Specifically, Ive no idea what is the size of the python-list
> readership -- surely in hundreds, more likely thousands.
>

Then it's part of, but the only side of, your public persona.

> So when I feel like making a response to one or two people which has
> more heat than (python-related) light, it would help to consider the
> thousand(s) who will read it who are not involved/interested in the
> fracas.

Don't be a little bitch, and respond. Instead you're whining about it.


>
> A more physical analogy: Lets say I am driving along happily on the
> freeway and someone does something to me that generates severe
> justifiable road-rage. So I stop the car, get down and do my schtick
> -- shout, shoot, mow-him-down, whatever -- and in the process create a
> jam of a hundred vehicles all around.  However justifiable my rage, I
> would be lucky to get anyone's support!

It's called information overload, and temporary insanity...go ask a lawyer list.


>
> A more personal point. I find that anger is usually a thin cover for
> depression.

A medical condition which can be cause by many different factors, and all legal.

And depression inversely correlates with amount of
> sunshine I see.

This is more seasonal depression, and human biological adjustment to
circadian rhythm in nature that appears in several areas.

 So before hitting the send button, it may be a good
> idea to sleep over and see if the rising sun changes my mood.

It always does, it's biological in nature for this to happen.

>
> Coming to threads like this one:
> We've seen an old member of this list scolded for stretching the
> drinking jokes a bit too far.

Probably me, and you have no idea what I'm not saying when if not
drinking I have severe nerve damage...that would probably blow your
own little itty bitty mind, so deal with average intelligence on your
own.

> And another old member who posted a youtube link which had nothing to
> do with python even though the subject said 'OT'
>
> So… Staying withing python-related discussions and using courteous
> language is the general rule for all. If you follow that you should be
> ok

Open mindedness is what the internet is about, if you can't be free
with emotions and internal vectors of molecular thought freedom, then
you might want ot move out of the way of the New World Order.



-- 
Best Regards,
David Hutto
CEO: http://www.hitwebdevelopment.com

[toc] | [prev] | [next] | [standalone]


#30149 — Re: Stop feeding the trolls (Was: which a is used?)

FromDwight Hutto <dwightdhutto@gmail.com>
Date2012-09-26 03:07 -0400
SubjectRe: Stop feeding the trolls (Was: which a is used?)
Message-ID<mailman.1396.1348643228.27098.python-list@python.org>
In reply to#30018
On Wed, Sep 26, 2012 at 3:06 AM, Dwight Hutto <dwightdhutto@gmail.com> wrote:
> You can "Plonk" my dick bitches.
>
>
> --
> Best Regards,
> David Hutto
> CEO: http://www.hitwebdevelopment.com



+5.75

[toc] | [prev] | [next] | [standalone]


#30076

From"Colin J. Williams" <cjw@ncf.ca>
Date2012-09-25 08:52 -0400
Message-ID<k3s9ho$fl1$1@theodyn.ncf.ca>
In reply to#29996
On 24/09/2012 10:14 PM, alex23 wrote:
> On Sep 25, 11:13 am, Dwight Hutto <dwightdhu...@gmail.com> wrote:
>> bitch
>
> I honestly could not care less what you think about me, but don't use
> that term. This isn't a boys' club and we don't need your hurt ego
> driving people away from here.
>
+1

[toc] | [prev] | [next] | [standalone]


#30016

FromThomas Rachel <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de>
Date2012-09-25 07:06 +0200
Message-ID<k3re5d$o2q$2@r03.glglgl.gl>
In reply to#29985
Am 25.09.2012 03:13 schrieb Dwight Hutto:

> Anything else bitch, take time to think about it.

And you wonder if people don't like you because of your language?


Thomas

[toc] | [prev] | [next] | [standalone]


#30020

FromDwight Hutto <dwightdhutto@gmail.com>
Date2012-09-25 01:22 -0400
Message-ID<mailman.1277.1348550537.27098.python-list@python.org>
In reply to#30016
On Tue, Sep 25, 2012 at 1:06 AM, Thomas Rachel
<nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de>
wrote:
> Am 25.09.2012 03:13 schrieb Dwight Hutto:
>
>
>> Anything else bitch, take time to think about it.
>
>
> And you wonder if people don't like you because of your language?
>

No, not really. If you wanna talk shit, I can reflect that, and if you
wanna talk politely I can reflect that. I go t attacked first., and
project managers don't get shoved around, they listen, respond, and if
wrong correct themselves, if not, they slam back , or their position
gets taken.
>
> Thomas
>
> --
> http://mail.python.org/mailman/listinfo/python-list



-- 
Best Regards,
David Hutto
CEO: http://www.hitwebdevelopment.com

[toc] | [prev] | [next] | [standalone]


#30025

FromThomas Rachel <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de>
Date2012-09-25 07:39 +0200
Message-ID<k3rg2b$q88$1@r03.glglgl.gl>
In reply to#30020
Am 25.09.2012 07:22 schrieb Dwight Hutto:

> No, not really. If you wanna talk shit, I can reflect that, and if you
> wanna talk politely I can reflect that. I go t attacked first.,

But not in this thread.

Some people read only selectively and see only your verbal assaults, 
without noticing that they refer to.

If you was really insulted, you should answer to these insults in their 
thread and not in a different one.


Thomas

[toc] | [prev] | [next] | [standalone]


#30013

FromTerry Reedy <tjreedy@udel.edu>
Date2012-09-25 01:05 -0400
Message-ID<mailman.1273.1348549542.27098.python-list@python.org>
In reply to#29973
Revising my answer to your other post.

On 9/24/2012 9:13 PM, Dwight Hutto wrote:
> Anything else bitch, take time to think about it.

This is completely bizarre, and uncalled for as an apparent response to 
Alex. Your next response is too dirty to read, let alone quote. Please 
desist. If necessary, learn to wait a few minutes before hitting send.


-- 
Terry Jan Reedy

[toc] | [prev] | [next] | [standalone]


#29988

FromSteven D'Aprano <steve+comp.lang.python@pearwood.info>
Date2012-09-25 01:18 +0000
Message-ID<50610671$0$29981$c3e8da3$5496439d@news.astraweb.com>
In reply to#29963
On Mon, 24 Sep 2012 16:43:24 -0700, Jayden wrote:

> Dear All,
> 
> I have a simple code as follows:
> 
> # Begin
> a = 1
> 
> def f():
>     print a
> 
> def g():
>     a = 20
>     f()
> 
> g()
> #End
> 
> I think the results should be 20, but it is 1. Would you please tell me
> why?

You are expecting "dynamic scoping", Python uses "static scoping" (or 
lexical scoping). With lexical scoping, you can reason about the 
behaviour of a function by knowing only how and where it is defined. The 
caller is irrelevant.

Since function f is defined globally, and does not have its own local 
variable a, it will always see the global variable a no matter where it 
is called. So when you call f() from inside g(), f prints 1, the global 
a, not 20, g's local a.

While dynamic scoping has its uses, it is more tricky to use correctly. 
One can no longer understand the behaviour of a function just by reading 
the function's own code, knowing where and how it is defined. You also 
need to know where it is called. A function f that works perfectly when 
you call it from functions g, h, k, ... will suddenly misbehave (crash, 
or worse, behave wrongly) when called from function v because v 
accidentally changes some global variable that f relies on.

This is especially a danger for Python, because built-in functions like 
len, chr, ord, print (version 3 only), and many others are all global 
variables.

(Technically, they are in a third scope, the builtins, but that's 
equivalent to being global.)



-- 
Steven

[toc] | [prev] | [next] | [standalone]


#29992

FromDwight Hutto <dwightdhutto@gmail.com>
Date2012-09-24 21:47 -0400
Message-ID<mailman.1263.1348537627.27098.python-list@python.org>
In reply to#29988
On Mon, Sep 24, 2012 at 9:18 PM, Steven D'Aprano
<steve+comp.lang.python@pearwood.info> wrote:
> On Mon, 24 Sep 2012 16:43:24 -0700, Jayden wrote:
>
>> Dear All,
>>
>> I have a simple code as follows:
>>
>> # Begin
>> a = 1
>>
>> def f():
>>     print a
>>Paul Rubin <no.email@nospam.invalid>
>> def g():
>>     a = 20
>>     f()
>>
>> g()
>> #End
>>
>> I think the results should be 20, but it is 1. Would you please tell me
>> why?
>
> You are expecting "dynamic scoping", Python uses "static scoping" (or
> lexical scoping). With lexical scoping, you can reason about the
> behavioPaul Rubin <no.email@nospam.invalid>ur of a function by knowing only how and where it is defined. The
> caller is irrelevant.
>
> Since fuPaul Rubin <no.email@nospam.invalid>nction f is defined globally, and does not have its own local
> variable a, it will always see the global variable a no matter where it
> is called. So when you call f() from inside g(), f prints 1, the global
> a, not 20, g's local a.
>
> While dynamic scoping has its uses, it is more tricky to use correctly.
> One can no longer understand the behaviour of a function just by reading
> the funcPaul Rubin <no.email@nospam.invalid>tion's own code, knowing where and how it is defined. You also
> need to know where it is called. A function f that works perfectly when
> you call it from functions g, h, k, ... will suddenly misbehave (crash,
> or worse, behave wrongly) when called from function v because v
> accidentally changes some global variable that f relies on.
>
> This is especially a danger for Python, because built-in functions like
> len, chr, ord, print (version 3 only), and many others are all global
> variables.
>
> (Technically, they are in a third scope, the builtins, but that's
> equivalent to being global.)
>

But within a class this is could be defined as self.x within the
functions and changed, correct?


class a():
	def __init__(self,a):
		self.a = a

	def f(self):
		print self.a

	def g(self):
		self.a = 20
		print self.a


a = a(1)
a.f()
a.g()


> --
> Steven
> --
> http://mail.python.org/mailman/listinfo/python-list



-- 
Best Regards,
David Hutto
CEO: http://www.hitwebdevelopment.com

[toc] | [prev] | [next] | [standalone]


#30017

FromThomas Rachel <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de>
Date2012-09-25 07:06 +0200
Message-ID<k3re4k$o2q$1@r03.glglgl.gl>
In reply to#29992
Am 25.09.2012 03:47 schrieb Dwight Hutto:

> But within a class this is could be defined as self.x within the
> functions and changed, correct?
>
>
> class a():
> 	def __init__(self,a):
> 		self.a = a
>
> 	def f(self):
> 		print self.a
>
> 	def g(self):
> 		self.a = 20
> 		print self.a
>
>
> a = a(1)
> a.f()
> a.g()

Yes - this is a different situation. Here, the "self" referred to is the 
same in all cases (the "a" from top level), and so self.a can be used 
consistently as well.


Thomas

[toc] | [prev] | [next] | [standalone]


#29993

FromDwight Hutto <dwightdhutto@gmail.com>
Date2012-09-24 21:50 -0400
Message-ID<mailman.1264.1348537858.27098.python-list@python.org>
In reply to#29988
But within a class this is could be defined as self.x within the
functions and changed, correct?


class a():
        def __init__(self,a):
                self.a = a

        def f(self):
                print self.a

        def g(self):
                self.a = 20
                print self.a


a = a(1)
a.f()
a.g()


Yielding:

david@david-desktop:~$ python answer_to_email.py
1
20
david@david-desktop:~$


-- 
Best Regards,
David Hutto
CEO: http://www.hitwebdevelopment.com

[toc] | [prev] | [next] | [standalone]


#30050

FromAlain Ketterlin <alain@dpt-info.u-strasbg.fr>
Date2012-09-25 11:30 +0200
Message-ID<871uhqih4h.fsf@dpt-info.u-strasbg.fr>
In reply to#29963
Jayden <jayden.shui@gmail.com> writes:

> # Begin
> a = 1
>
> def f():
>     print a
>
> def g():
>     a = 20
>     f()
>
> g()
> #End
>
> I think the results should be 20, but it is 1. Would you please tell me why?

When python looks at g(), it sees that a variable a is assigned to, and
decides it is a local variable. When it looks at f(), it sees a use of a
but no assignment, so it decides it is a global variable and fetches the
value from the outer scope.

If you change f() to:

def f():
    print a
    a = 30

you change a into a local variable (and get another error).

If you want to change the binding of a in g(), you can declare it
global:

def g():
    global a
    a = 20
    f()

Very tricky, actually.

-- Alain.

[toc] | [prev] | [standalone]


Page 2 of 2 — ← Prev page 1 [2]

Back to top | Article view | comp.lang.python


csiph-web