Re: which a is used?

2012-09-25 Thread Mark Lawrence

On 25/09/2012 06:07, Thomas Rachel wrote:

Am 25.09.2012 04:37 schrieb Dwight Hutto:

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.


OH. stirrin up shit and can't stand the smell.


Where did he so?


Thomas


He's referring to threads on the tutor mailing list where I have 
repeatedly asking him to provide context when he replies.  Unfortunately 
he doesn't seem to understand the term context so resorts to attacking 
me.  In a part of one thread he referred to my family as pigs.  I've 
have lived with that, using the sticks and stones reply, but then 
someone had the audacity to protect his stance.  I am sure that people 
have seen enough of his behaviour in the last few hours to see the real 
Dwight Hutto so I'll leave it at that.


--
Cheers.

Mark Lawrence.

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


Re: which a is used?

2012-09-25 Thread Alain Ketterlin
Jayden jayden.s...@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.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: which a is used?

2012-09-25 Thread alex23
On Sep 25, 3:30 pm, Dwight Hutto dwightdhu...@gmail.com wrote:
 You'd have to read the other posts. And remember that some of these
 names are A.K.A.'s, they ask respond, and befriend another name
 through another proxy.

You've actively accused me of this several times. If you have evidence
that there's sockpuppeting, please provide it.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: which a is used?

2012-09-25 Thread Colin J. Williams

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
--
http://mail.python.org/mailman/listinfo/python-list


Re: which a is used?

2012-09-24 Thread Dwight Hutto
On Mon, Sep 24, 2012 at 7:43 PM, Jayden jayden.s...@gmail.com 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?

 Thanks a lot!

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

didn't return the value, or print it out


-- 
Best Regards,
David Hutto
CEO: http://www.hitwebdevelopment.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: which a is used?

2012-09-24 Thread Dwight Hutto
On Mon, Sep 24, 2012 at 7:57 PM, Dwight Hutto dwightdhu...@gmail.com wrote:
 On Mon, Sep 24, 2012 at 7:43 PM, Jayden jayden.s...@gmail.com wrote:
 Dear All,

 I have a simple code as follows:

 # Begin
 a = 1

 def f():
 print a

 def g():
 a = 20
 f()

this prints a from calling f() function

call print a wasn't in a class where it was self.a and changed, so it
performed the function f which prints a and a = 1, but g just assigns
the 20, and calls the f() function which shows a, there is no self.a,
nor a class to show this in.




 g()
 #End

 I think the results should be 20, but it is 1. Would you please tell me why?

 Thanks a lot!

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

 didn't return the value, or print it out


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



-- 
Best Regards,
David Hutto
CEO: http://www.hitwebdevelopment.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: which a is used?

2012-09-24 Thread alex23
On Sep 25, 9:43 am, Jayden jayden.s...@gmail.com 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?

Because you don't declare 'a' in 'f', it looks for 'a' in the
surrounding scope _where it was defined_, not where it was called.
Because 'a' in the module scope is 1, you'll get 1.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: which a is used?

2012-09-24 Thread Dwight Hutto
Anything else bitch, take time to think about it.
-- 
Best Regards,
David Hutto
CEO: http://www.hitwebdevelopment.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: which a is used?

2012-09-24 Thread Steven D'Aprano
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
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: which a is used?

2012-09-24 Thread Dwight Hutto
On Mon, Sep 24, 2012 at 9:18 PM, Steven D'Aprano
steve+comp.lang.pyt...@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.invalidur of a function by knowing only 
 how and where it is defined. The
 caller is irrelevant.

 Since fuPaul Rubin no.email@nospam.invalidnction 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.invalidtion'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
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: which a is used?

2012-09-24 Thread 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()


Yielding:

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


-- 
Best Regards,
David Hutto
CEO: http://www.hitwebdevelopment.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: which a is used?

2012-09-24 Thread alex23
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.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: which a is used?

2012-09-24 Thread Dwight Hutto
 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.

OH. stirrin up shit and can't stand the smell. Turn and
switch technique. You're so vulgar, and I wasn't.Go get a clue ho,
and then you can gumshoe it up the last crack alley on the left, and
suck till my nut hair tickles your tonsils.




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



-- 
Best Regards,
David Hutto
CEO: http://www.hitwebdevelopment.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: which a is used?

2012-09-24 Thread Terry Reedy

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

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


Re: which a is used?

2012-09-24 Thread Thomas Rachel

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
--
http://mail.python.org/mailman/listinfo/python-list


Re: which a is used?

2012-09-24 Thread Thomas Rachel

Am 25.09.2012 04:37 schrieb Dwight Hutto:

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.


OH. stirrin up shit and can't stand the smell.


Where did he so?


Thomas
--
http://mail.python.org/mailman/listinfo/python-list


Re: which a is used?

2012-09-24 Thread Dwight Hutto
On Tue, Sep 25, 2012 at 1:06 AM, Thomas Rachel
nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa...@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
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: which a is used?

2012-09-24 Thread Dwight Hutto
 OH. stirrin up shit and can't stand the smell.


 Where did he so?



You'd have to read the other posts. And remember that some of these
names are A.K.A.'s, they ask respond, and befriend another name
through another proxy.


-- 
Best Regards,
David Hutto
CEO: http://www.hitwebdevelopment.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: which a is used?

2012-09-24 Thread Thomas Rachel

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
--
http://mail.python.org/mailman/listinfo/python-list