Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Python (http://www.velocityreviews.com/forums/f43-python.html)
-   -   Newbie Question: Abstract Class in Python (http://www.velocityreviews.com/forums/t319324-newbie-question-abstract-class-in-python.html)

Kevin Bass 07-07-2003 12:10 AM

Newbie Question: Abstract Class in Python
 
Hello:

I am new to Python and want to know how to implement an abstract class? I
have read through different books and I have no found this information.
Thanks!

Kevin



Aahz 07-07-2003 12:20 AM

Re: Newbie Question: Abstract Class in Python
 
In article <5U2Oa.239646$jp.6482027@twister.southeast.rr.com> ,
Kevin Bass <kbass1@nc.rr.com> wrote:
>
>I am new to Python and want to know how to implement an abstract
>class? I have read through different books and I have no found this
>information. Thanks!


Simple answer: you don't. Python doesn't really have that concept. If
you tell us what you're trying to do, we can explain how to do that in
Python.
--
Aahz (aahz@pythoncraft.com) <*> http://www.pythoncraft.com/

"Not everything in life has a clue in front of it...." --JMS

Erik Max Francis 07-07-2003 12:40 AM

Re: Newbie Question: Abstract Class in Python
 
Kevin Bass wrote:

> I am new to Python and want to know how to implement an abstract
> class? I
> have read through different books and I have no found this
> information.
> Thanks!


There's no builtin way to do that in Python. Typically if I'm doing
something where I want to make a class that yells at me if I 1.
accidentally instantiate it directly or 2. fail to override one of its
methods in a subclass, I do something like:

class AbstractSomething:
def __init__(self):
if self.__class__ is AbstractSomething:
raise NotImplementedError

def aMethod(self, ...):
raise NotImplementedError

def anotherMethod(self, ...):
raise NotImplementedError

--
Erik Max Francis && max@alcyone.com && http://www.alcyone.com/max/
__ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE
/ \ They love too much that die for love.
\__/ (an English proverb)

Ben Finney 07-07-2003 01:00 AM

Re: Newbie Question: Abstract Class in Python
 
On Mon, 07 Jul 2003 00:42:27 GMT, Kevin Bass wrote:
> I am only looking for an answer about creating an abstract class in
> Python and not a solution to a problem. I am looking for a way to
> stop class instantiation of a class. This should be a generic
> approach.


Python, in general, doesn't try to stop the programmer doing things, the
way many other languages do. This is known in the community as the
"we're all consenting adults" philosophy.

If you can tell us why you'd want to prevent class instantiation, we can
discuss that.

--
\ "It's a good thing we have gravity or else when birds died |
`\ they'd just stay right up there. Hunters would be all |
_o__) confused." -- Steven Wright |
http://bignose.squidly.org/ 9CFE12B0 791A4267 887F520C B7AC2E51 BD41714B


All times are GMT. The time now is 06:16 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.