Quoth walterbyrd :
> For a language as well structured as Python, this seems somewhat
> sloppy, and inconsistant. Or is there some good reason for this?
Yes. It's called Object Oriented Programming.
> Here is what I mean:
>
> def a():
> x = 99
> print x
>
> def b():
> print x
>
>
For a language as well structured as Python, this seems somewhat
sloppy, and inconsistant. Or is there some good reason for this?
Here is what I mean:
def a():
x = 99
print x
def b():
print x
a()
b() # raises an exception because x is not defined.
However in the methods are within
I think there is a simpler answer to all this(not to take away from
the other ones here though which are all great). When writing
procedural code how would you like it if vars inside functions were
automatically global. Your code with be blowing chunks in no time.
Thats the reason for global declar
"walterbyrd" wrote in message
news:518b9dd9-69c5-4d5b-bd5f-ad567be62...@b38g2000prf.googlegroups.com...
> However in the methods are within a class, the scoping seems to work
> differently.
Not really, self is a formal parameter to the function. It would be
a strange language where a function'
On Dec 18, 2:19 am, walterbyrd wrote:
> For a language as well structured as Python, this seems somewhat
> sloppy, and inconsistant. Or is there some good reason for this?
>
> Here is what I mean:
>
> def a():
> x = 99
> print x
>
> def b():
> print x
>
> a()
> b() # raises an excepti
On Dec 17, 10:00 am, r wrote:
> When writing
> procedural code how would you like it if vars inside functions were
> automatically global. Your code with be blowing chunks in no time.
That was my point - I consider python's ordinary use of lexical
scoping to be a good thing, and I was wondering w
On Dec 17, 9:04 am, rdmur...@bitdance.com wrote:
> Yes. It's called Object Oriented Programming.
I think you mean it's *Python* Object Oriented Programming. I am not
sure that every other OO language works like that.
--
http://mail.python.org/mailman/listinfo/python-list
On Dec 17, 10:17 am, "Richard Brodie" wrote:
> Not really, self is a formal parameter to the function. It would be
> a strange language where a function's own arguments weren't in scope.
Thank you, that makes sense to me.
--
http://mail.python.org/mailman/listinfo/python-list
On Dec 17, 12:20 pm, walterbyrd wrote:
> On Dec 17, 10:00 am, r wrote:
>
> > When writing
> > procedural code how would you like it if vars inside functions were
> > automatically global. Your code with be blowing chunks in no time.
>
> That was my point - I consider python's ordinary use of lexi
On Dec 17, 8:41 am, prueba...@latinmail.com wrote:
> If scoping worked as you want, how, pray tell, would you define object
> attributes?- Hide quoted text -
I suppose you could do this:
class className():
varname = "whatever"
def fname(self, varname):
. . . .
Instead of having v
On Dec 17, 10:19 am, walterbyrd wrote:
> For a language as well structured as Python, this seems somewhat
> sloppy, and inconsistant. Or is there some good reason for this?
>
> Here is what I mean:
>
> def a():
> x = 99
> print x
>
> def b():
> print x
>
> a()
> b() # raises an except
walterbyrd wrote:
> For a language as well structured as Python, this seems somewhat
> sloppy, and inconsistant. Or is there some good reason for this?
>
> Here is what I mean:
>
> def a():
> x = 99
> print x
>
> def b():
> print x
>
> a()
> b() # raises an exception because x is
walterbyrd a écrit :
On Dec 17, 8:41 am, prueba...@latinmail.com wrote:
If scoping worked as you want, how, pray tell, would you define object
attributes?- Hide quoted text -
I suppose you could do this:
class className():
varname = "whatever"
This defines a class attribute - that is,
walterbyrd a écrit :
On Dec 17, 9:04 am, rdmur...@bitdance.com wrote:
Yes. It's called Object Oriented Programming.
I think you mean it's *Python* Object Oriented Programming. I am not
sure that every other OO language works like that.
Every OO languages having such a thing as a global va
On Wed, 17 Dec 2008 15:19:32 -, walterbyrd
wrote:
However in the methods are within a class, the scoping seems to work
differently.
Not really. Hopefully this commentary will show you why.
class ab():
def a(self):
self.x = 99
print self.x
def b(self):
On Wed, Dec 17, 2008 at 4:03 PM, Rhodri James
wrote:
> On Wed, 17 Dec 2008 15:19:32 -, walterbyrd wrote:
>
>> However in the methods are within a class, the scoping seems to work
>> differently.
>
> Not really. Hopefully this commentary will show you why.
>
>> class ab():
>>def a(self):
On Wed, 17 Dec 2008 22:19:43 +0100, Bruno Desthuilliers wrote:
> Your
> problem is that you are confusing variables and attributes. In Python,
> 'anything.anyname' (note the dot) is the attribute 'anyname' of object
> 'anything'.
An easy mistake to make, given that scopes are just namespaces, and
On Wed, 17 Dec 2008 10:20:21 -0800, walterbyrd wrote:
> On Dec 17, 10:00 am, r wrote:
>> When writing
>> procedural code how would you like it if vars inside functions were
>> automatically global. Your code with be blowing chunks in no time.
>
> That was my point - I consider python's ordinary
18 matches
Mail list logo