Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Creating subclassess (newbie)

Reply
Thread Tools

Creating subclassess (newbie)

 
 
Adam
Guest
Posts: n/a
 
      06-21-2004
I have tried to send this to the tutor mailing list, but it
seems to be down at the moment.

I have a subclass I want to create- my intuition told me
that it would be done like this:

class MainClass:
class SubClass:
code...
subclassinstance = SubClass()
mainclassinstance = MainClass()

But it seems that this isn't going to work. I'm reading a
couple of Python books, but they don't seem to cover this
topic very well (I don't see any coding examples).

What is the best way of creating (coding) subclasses?
Alternatively, is there any good documentation on the web
for doing this?

Thanks in advance.

Adam
 
Reply With Quote
 
 
 
 
Peter Hansen
Guest
Posts: n/a
 
      06-21-2004
Adam wrote:

> I have a subclass I want to create- my intuition told me
> that it would be done like this:
>
> class MainClass:
> class SubClass:
> code...
> subclassinstance = SubClass()
> mainclassinstance = MainClass()


Have you followed through the tutorial in the documentation?
The section on classes covers inheritance in a basic way.
See
http://www.python.org/doc/current/tu...00000000000000

-Peter
 
Reply With Quote
 
 
 
 
Duncan Booth
Guest
Posts: n/a
 
      06-21-2004
Adam <(E-Mail Removed)> wrote in news:20040621153854.14f10a9f@debian:

> What is the best way of creating (coding) subclasses?
> Alternatively, is there any good documentation on the web
> for doing this?
>


Have you tried reading the Python tutorial? http://docs.python.org/tut if
you can't find it on your own machine. Try reading chapter 9: 'classes'
with special attention to 9.5 'inheritance'.

If you want coding examples you could look at Python's standard library.
There are plenty of examples of subclassing. For example, try CGIHTTPServer
and its associated documentation, htmllib or HTMLParser are other places
to look.

http://docs.python.org/lib/htmlparser-example.html shows an example of
subclassing the HTMLParser class to parse html.
 
Reply With Quote
 
Lonnie Princehouse
Guest
Posts: n/a
 
      06-21-2004
Typically, "subclass" refers to a derived class. It looks like you've
interpreted it in a different way, to mean a class that is a member of
another class? Interesting =)

subclass example-

class MainClass:
def foo(self):
return 'main_foo'
def bar(self):
return 'main_bar'

class SubClass(MainClass):
def foo(self):
return 'sub_foo'

>>> x = SubClass()
>>> print x.foo()

sub_foo
>>> print x.bar()

main_bar







Adam <(E-Mail Removed)> wrote in message news:<20040621153854.14f10a9f@debian>...
> I have tried to send this to the tutor mailing list, but it
> seems to be down at the moment.
>
> I have a subclass I want to create- my intuition told me
> that it would be done like this:
>
> class MainClass:
> class SubClass:
> code...
> subclassinstance = SubClass()
> mainclassinstance = MainClass()
>
> But it seems that this isn't going to work. I'm reading a
> couple of Python books, but they don't seem to cover this
> topic very well (I don't see any coding examples).
>
> What is the best way of creating (coding) subclasses?
> Alternatively, is there any good documentation on the web
> for doing this?
>
> Thanks in advance.
>
> Adam

 
Reply With Quote
 
Piet van Oostrum
Guest
Posts: n/a
 
      06-23-2004
>>>>> Adam <(E-Mail Removed)> (A) wrote:

A> I have tried to send this to the tutor mailing list, but it
A> seems to be down at the moment.

A> I have a subclass I want to create- my intuition told me
A> that it would be done like this:

A> class MainClass:
A> class SubClass:
A> code...
A> subclassinstance = SubClass()
A> mainclassinstance = MainClass()

A> But it seems that this isn't going to work. I'm reading a
A> couple of Python books, but they don't seem to cover this
A> topic very well (I don't see any coding examples).

I can't imagine that the Python books don't tell this.

A> What is the best way of creating (coding) subclasses?
A> Alternatively, is there any good documentation on the web
A> for doing this?

I guess every Python introduction tells you:

class MainClass:
....

class SubClass(MainClass):
....

mainclassinstance = MainClass()
subclassinstance = SubClass()
--
Piet van Oostrum <(E-Mail Removed)>
URL: http://www.cs.uu.nl/~piet [PGP]
Private email: http://www.velocityreviews.com/forums/(E-Mail Removed)
 
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
"Error Creating Control" when creating a custom control (Design Time). Can't see tooltip message. Ravi Ambros Wallau ASP .Net Web Controls 0 06-01-2005 02:36 PM
"Error Creating Control" when creating a custom control (Design Time). Can't see tooltip message. Ravi Ambros Wallau ASP .Net 0 06-01-2005 02:36 PM
Re: Creating a network with a single wireless computer Pavel A. Wireless Networking 1 08-03-2004 12:19 AM
Re: Creating a network with a single wireless computer Tim Levy Wireless Networking 0 08-02-2004 07:32 PM
creating Network Traffic Wireless Networking 1 07-06-2004 03:52 PM



Advertisments