Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Instantiating Classes in python (newbie)

Reply
Thread Tools

Instantiating Classes in python (newbie)

 
 
DaBeef
Guest
Posts: n/a
 
      10-31-2005
Hello, I am learning python for work from knowing java,c#,c. I had a
couple questions.
1) IntegerClass - to instantiate this class how come I use i =
IntegerClass.IntegerClass() and then this works while i =
IntegerClass() i.method. I receive an error.

2) Also using self in the method (self, dataVal). What does this do
differently from using (dataval). I am a little confused about the
bound and unbound methods. What does passing self do different?
Thank-you for all your help

 
Reply With Quote
 
 
 
 
infidel
Guest
Posts: n/a
 
      10-31-2005
> Hello, I am learning python for work from knowing java,c#,c. I had a
> couple questions.
> 1) IntegerClass - to instantiate this class how come I use i =
> IntegerClass.IntegerClass() and then this works while i =
> IntegerClass() i.method. I receive an error.


It depends on what IntegerClass is. If you have a module named
IntegerClass with a class named IntegerClass within it, then you must
use IntegerClass.IntegerClass to refer to the class, because
IntegerClass is the module. You could also change the import statement
to:

from IntegerClass import IntegerClass

.... in which case, IntegerClass in your current namespace will be the
class and not the module.

This is all an educated guess because you didn't specify what the error
was.

> 2) Also using self in the method (self, dataVal). What does this do
> differently from using (dataval). I am a little confused about the
> bound and unbound methods. What does passing self do different?
> Thank-you for all your help


A bound method is kind of like an instance method in java, it's "bound"
to a particular instance object. Python automatically inserts a
reference to the object itself as the first argument to a bound call.
"self" is just like "this" in Java, but you have to explicitly account
for it in the method signature.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Uses for "self-instantiating classes"? David Karr Javascript 5 09-01-2009 05:56 PM
Instantiating classes / sharing data between classes Trevoke Ruby 10 07-22-2009 09:21 PM
instantiating random sub-classes (Dragon, TeethDeer, etc) Thufir Ruby 4 11-08-2007 04:10 AM
Is there a good example on instantiating, calling, using, an API from Python on Windows? kj7ny Python 3 01-12-2007 10:07 AM
Instantiating classes which are derived from built-in types. Alex Martelli Python 3 11-29-2005 08:01 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57