Re: Chapter 9 Tutorial for Classes Not Working



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'


From here I run:
>
x = MyClass

the tutorial says:

Class instantiation uses function notation. Just pretend that the
class object is a parameterless function that returns a new
instance of the class. For example (assuming the above class):

x = MyClass()

creates a new instance of the class and assigns this object to the
local variable x.

</F>

.



Relevant Pages

  • Re: Is there a possibility to include methods of a class?
    ... class Myclass < ActiveRecord::Base ... def self.find ... that with another object which represents a row in a local SQL database. ... But this doesn't re-use *any* of ActiveRecord. ...
    (comp.lang.ruby)
  • Re: define and call methods in ruby
    ... def method_to_call ... It's the object that can execute the method. ... Thanks David for the help, but just kinda suprised, wouldn't it be for ...
    (comp.lang.ruby)
  • Re: calling class methods without instance
    ... > def printSomething: ... Just copied your code above and pasted into a python console session: ...
    (comp.lang.python)
  • Re: Looking for assignement operator
    ... The recursion problem doesn't occur with you original code (for the good ... class MyClass: ... def setval: ... I did test this on Python 2.4.3 in Mac OS X 10.4 and it worked fine. ...
    (comp.lang.python)
  • Re: namespace question
    ... def myFun: ... calling the same variables or using the same functions/classes from numpy, ... The functions in module "test" will access that module's namespace, not that of the calling module. ...
    (comp.lang.python)