instances

Paddy paddy3118 at netscape.net
Fri Jul 14 14:36:05 EDT 2006


Quenton Bonds wrote:
> Hello
> I am trying to understand the abilities and limitation of creating an
> instance.  First I will give you my understanding then please steer me
> in the right direction.
>
> Abiities
> 1.  The two ways to create an instance is def method(self) &
> __int__(self, other, instances,...)
> 2.  By creating an instance of a method; the functions of that method
> can be used through out the
>    program in a fashion such as self.methodofprogram(parameters)
> Limitations
> 3.  One cannot create an instance of a class.
> 4.  An instance can only perform functions that are provided from the
> method it was instanced from.
>
> 5.  Is there any other key information I am missing.
Hi Quentin,
Might you be new to programming, or new to Object Oriented programming?
You might profit from reading some of the beginners tutorials mentioned
here:
  http://wiki.python.org/moin/BeginnersGuide
which points to
  http://wiki.python.org/moin/BeginnersGuide/NonProgrammers

Here is some info to correct your statements above (but it is not a
tutorial)!

The class statement creates a 'class definition'.
E.g:
  class my_class():
    pass
Instances of a class are created by using the class name followed by
parenthesis,
E.g:
  my_inst = my_class()

If a class has methods:
  class my_class2:
    def my_method(self):
      pass
Then an instance of the class:
  my_inst2 = my_class2()
Can access its method like this:
  my_inst2.my_method()

Trying to access a method of the class that does not exist will produce
an error.
E.g:
  my_inst2.missing_method()
Will give an error, (throw an exception in Python terminology)..

The above is just a (poor) taste. Dive into one of the beginners
tutorials.

- Pad.




More information about the Python-list mailing list