Re: Chapter 9 Tutorial for Classes Not Working

2006-06-30 Thread John Salerno
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

Re: Chapter 9 Tutorial for Classes Not Working

2006-06-30 Thread tac-tics
> 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

Re: Chapter 9 Tutorial for Classes Not Working

2006-06-30 Thread Ant
> 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

Re: Chapter 9 Tutorial for Classes Not Working

2006-06-30 Thread Fredrik Lundh
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' > >

Re: Chapter 9 Tutorial for Classes Not Working

2006-06-30 Thread Damjan
> 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

Chapter 9 Tutorial for Classes Not Working

2006-06-30 Thread Tom Grove
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