tac-tics wrote:
>> x = MyClass
>> xf = x.f
>> while True:
>>print xf()
>
> Python has some VERY nasty gotchas concerning parenthesis (or lack
> there of).
Is this really a gotcha? I don't think you should blame Python for this
mistake. Even a novice programmer like myself can
> x = MyClass
> xf = x.f
> while True:
>print xf()
Python has some VERY nasty gotchas concerning parenthesis (or lack
there of).
In the first line here, you assign x = MyClass. That means x becomes an
alias for the class MyClass. not an object like you intended. Look
back
> class MyClass:
> "A simple example class"
> i = 12345
> def f(self):
> return 'hello world'
Nothing wrong with this.
> From here I run:
> x = MyClass
Here's your problem - x is a class, *not* an instance of a class (i.e.
an object). Methods
operate on objects, not clas
Tom Grove wrote:
> I am trying the classes example from the tutorial because some other
> class related stuff I am doing is not working either.
>
> Straight from Chapter 9:
>
> class MyClass:
> "A simple example class"
> i = 12345
> def f(self):
> return 'hello world'
>
>
> class MyClass:
> "A simple example class"
> i = 12345
> def f(self):
> return 'hello world'
>
>
> From here I run:
> x = MyClass
Did you mean x = MyClass()
> xf = x.f
> while True:
>print xf()
>
> This gives the following error:
>
> Traceback (most r
Here is my version:
Python 2.4.3 (#2, May 9 2006, 21:56:54)
[GCC 3.4.4 [FreeBSD] 20050518] on freebsd6
I am trying the classes example from the tutorial because some other
class related stuff I am doing is not working either.
Straight from Chapter 9:
class MyClass:
"A simple example class