Chapter 9 Tutorial for Classes Not Working



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"
i = 12345
def f(self):
return 'hello world'


From here I run:
x = MyClass
xf = x.f
while True:
print xf()

This gives the following error:

Traceback (most recent call last):
File "<stdin>", line 2, in ?
TypeError: unbound method f() must be called with MyClass instance as first argument (got nothing instead)

Please help...this is killing me!

-Tom
.



Relevant Pages

  • Re: A quick is this safe singleton question
    ... static readonly myClass instance = new myClass; ... public static myClass Instance ... _someObj = new SomeClass; ... constructor. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: super.clone() puzzlement
    ... public class MyClass { ... public MyClass(MyClass mine) { ... That is, I want a copy of the MyClass instance where, when I change the object referenced by its value, a copy I've made of the MyClass instance keeps its own value object intact. ... public MyClass(T value, ValueCopier<T> copier) { ...
    (comp.lang.java.programmer)
  • Re: Stupid question about List(Of T)
    ... Dim MyList as New List(Of MyClass) ... dim TempC as new MyClass ... Do fun stuff and set TempC.ThisProperty and TempC.ThatProperty ... you are disposing each MyClass instance after you add it to the list. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: super.clone() puzzlement
    ... public class MyClass { ... public MyClass(MyClass mine) { ... That is, I want a copy of the MyClass instance where, when I change the object referenced by its value, a copy I've made of the MyClass instance keeps its own value object intact. ...
    (comp.lang.java.programmer)
  • Re: super.clone() puzzlement
    ... public class MyClass { ... public MyClass(MyClass mine) { ... That is, I want a copy of the MyClass instance where, when I change the object referenced by its value, a copy I've made of the MyClass instance keeps its own value object intact. ...
    (comp.lang.java.programmer)