Chris Angelico於 2019年5月18日星期六 UTC+8下午3時09分37秒寫道:
> On Sat, May 18, 2019 at 1:51 PM wrote:
> >
> > Correct me if I am wrong, please.
> >
> > I always think that the LEGB rule (e.g. the namespace to look up for) was
> > applied at compile-time, only the binding was resolved "dynamically" at
> > ru
On Sat, May 18, 2019 at 1:51 PM wrote:
>
> Correct me if I am wrong, please.
>
> I always think that the LEGB rule (e.g. the namespace to look up for) was
> applied at compile-time, only the binding was resolved "dynamically" at
> run-time. For example:
>
> def foo():
> print(x)
>
> foo() wi
Irv Kalb writes:
> ...
> The only thing that threw me was that in a line like:
>
> self.x = self.x + 1
>
> in a method, these two uses of self.x can refer to different variables. I
> actually teach Python, and this would be a very difficult thing to explain to
> students.
>
> I have never run
Correct me if I am wrong, please.
I always think that the LEGB rule (e.g. the namespace to look up for) was
applied at compile-time, only the binding was resolved "dynamically" at
run-time. For example:
def foo():
print(x)
foo() will cause a NameError. But after
x = 5
foo() will run corr
On 05/17/2019 11:37 AM, Irv Kalb wrote:
self.x = self.x + 1
I have never run across this issue because I would never use the same name as
an instance attribute and a class attribute.
So you treat your class attributes as if they were static?
--
~Ethan~
--
https://mail.python.org/mailman/lis
On Sat, May 18, 2019 at 4:40 AM Irv Kalb wrote:
>
> Thanks for your comments. I am very aware of all the other issues that you
> explained.
>
> The only thing that threw me was that in a line like:
>
> self.x = self.x + 1
>
> in a method, these two uses of self.x can refer to different variables
> On May 15, 2019, at 5:41 PM, Ben Finney wrote:
>
> Irv Kalb writes:
>
>> I just saw some code that confused me. The confusion has to do with
>> class variables and instance variables.
>
> (Perhaps unrelated, but here's another confusion you may be suffering
> from: There's no such thing as
Irv Kalb writes:
> I just saw some code that confused me. The confusion has to do with
> class variables and instance variables.
(Perhaps unrelated, but here's another confusion you may be suffering
from: There's no such thing as a “class variable” or “instance
variable”. In Python, a “variable
> On May 15, 2019, at 11:02 AM, Rob Gaddi
> wrote:
>
> On 5/15/19 10:52 AM, Irv Kalb wrote:
>> I just saw some code that confused me. The confusion has to do with class
>> variables and instance variables. In order to understand it better, I built
>> this very small example:
>> class Test:
On 5/15/19 10:52 AM, Irv Kalb wrote:
I just saw some code that confused me. The confusion has to do with class
variables and instance variables. In order to understand it better, I built
this very small example:
class Test:
x = 0
def __init__(self, id):
self.id = id
I just saw some code that confused me. The confusion has to do with class
variables and instance variables. In order to understand it better, I built
this very small example:
class Test:
x = 0
def __init__(self, id):
self.id = id
self.show()
def show(self):
11 matches
Mail list logo