[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.python

What is a class?

Aaron Brady

3/5/2008 6:50:00 PM

What is a class that is not a module?
34 Answers

Paul McGuire

3/5/2008 7:30:00 PM

0

On Mar 5, 12:50 pm, castiro...@gmail.com wrote:
> What is a class that is not a module?

Please stop posting these one-liner beginner questions. If you can
type it in one line, you can enter it on the Google.com or Ask.com
query page and get a wealth of *existing* information, from tutorials,
documentation, online presentations. If you are able to phrase such a
question, you are capable of doing a little research and
experimentation on your own.

These posts translate to "I'm too lazy to use Google, or too cheap to
buy a Python book, or too lazy to read it, or too impatient to do my
own experimenting - much better to just post on c.l.py and have the
answer spoon-fed to me!"

I refuse to spoon feed you the answer to this question when plenty of
supporting material is already available.

-- Paul

Aaron Brady

3/5/2008 8:05:00 PM

0

On Mar 5, 1:29 pm, Paul McGuire <pt...@austin.rr.com> wrote:
> On Mar 5, 12:50 pm, castiro...@gmail.com wrote:
>
> > What is a class that is not a module?
>
> Please stop posting these one-liner beginner questions.  If you can
> type it in one line, you can enter it on the Google.com or Ask.com
> query page and get a wealth of *existing* information, from tutorials,
> documentation, online presentations.  If you are able to phrase such a
> question, you are capable of doing a little research and
> experimentation on your own.
>
> These posts translate to "I'm too lazy to use Google, or too cheap to
> buy a Python book, or too lazy to read it, or too impatient to do my
> own experimenting - much better to just post on c.l.py and have the
> answer spoon-fed to me!"
>
> I refuse to spoon feed you the answer to this question when plenty of
> supporting material is already available.

In the future, shall I assume that other readers here have no ideas
(on this, read *ever*), that haven't already been published? 'Cause I
have.

For instance, in this example, I've tried a few approaches that didn't
turn out well.

Do you want a comparison of existing solutions? Do you have a proof
that they exhaust the solution space?

I'm willing to address convention, in serial or parallel--- (change
subject to 'what goes on newsgroups'?), but it's not clear from fact
what assumption who has made.

Next time, why don't you say, "How much experience do you have?", or
"What level should I gear my answer toward?"

Paul McGuire

3/5/2008 9:13:00 PM

0

On Mar 5, 2:04 pm, castiro...@gmail.com wrote:
> On Mar 5, 1:29 pm, Paul McGuire <pt...@austin.rr.com> wrote:
>
> > On Mar 5, 12:50 pm, castiro...@gmail.com wrote:
>
> > > What is a class that is not a module?
>
> > Please stop posting these one-liner beginner questions.  If you can
> > type it in one line, you can enter it on the Google.com or Ask.com
> > query page and get a wealth of *existing* information, from tutorials,
> > documentation, online presentations.  If you are able to phrase such a
> > question, you are capable of doing a little research and
> > experimentation on your own.
>
> > These posts translate to "I'm too lazy to use Google, or too cheap to
> > buy a Python book, or too lazy to read it, or too impatient to do my
> > own experimenting - much better to just post on c.l.py and have the
> > answer spoon-fed to me!"
>
> > I refuse to spoon feed you the answer to this question when plenty of
> > supporting material is already available.
>
> In the future, shall I assume that other readers here have no ideas
> (on this, read *ever*), that haven't already been published?  'Cause I
> have.
>
> For instance, in this example, I've tried a few approaches that didn't
> turn out well.
>
Fair game. Capture one of these classes (or better, distill it down
to a *small* example demonstrating the problem), tell us what you are
trying to achieve, post it, AND tell us what is "not turning out
well." (Your previous posts have done a poor job in providing one or
more of these elements.)

> Do you want a comparison of existing solutions?  Do you have a proof
> that they exhaust the solution space?
>
*I* don't want *any* such thing, especially on the topics of "what is
a class?" and "how is a class different from a module?", nor do I need
proof that the basic background info on this topic covers the
mainstream applications of classes and modules. These are basic OO
concepts in Python. Try googling "python object-oriented". And if
there were some esoteric aspect of "what is a class?" that you want to
pursue that might not be covered in the available material, I would
expect one to include that in the original post.

> I'm willing to address convention, in serial or parallel--- (change
> subject to 'what goes on newsgroups'?), but it's not clear from fact
> what assumption who has made.
>
Since you did not elaborate on what your efforts were and the extent
they were undesirable (certainly useful info from someone honestly
interested in a helpful answer), I assumed you had made none.

> Next time, why don't you say, "How much experience do you have?", or
> "What level should I gear my answer toward?"
>
I put the onus on the poster to realize that the question they are
asking is in fact a basic concept, *especially* when the subject of
the question is captured in a built-in method, type, class, or
keyword. Surely you are aware that Python has been around for a
number of years, and that in all that time, it is entirely likely that
the topic of "what is a class?" has been covered, in any number of the
tutorials and docs so charitably written by many of the contributors
in this newsgroup.

Please stop asking those people to further expend their time repeating
this work just for your benefit. It is like arriving late to a
meeting, and asking everyone to stop and bring you up to speed on what
you missed, in effect saying, "My time is more valuable than yours, I
can't be bothered to arrive on time, or do even the simplest research
for myself."

-- Paul

Mike Driscoll

3/5/2008 9:39:00 PM

0

On Mar 5, 12:50 pm, castiro...@gmail.com wrote:
> What is a class that is not a module?

Why is a raven like a writing desk?

As for Python class information, I would recommend reading the
following sites:

http://docs.python.org/tut/n...
http://www.diveintopython.org/object_oriented_framework/defining_cl...

And for modules, check these out:

http://docs.python.org/tut/...
http://www.penzilla.net/tutorials/pytho...

Mike

Aaron Brady

3/5/2008 9:49:00 PM

0

> > > > What is a class that is not a module?
>
> > I'm willing to address convention, in serial or parallel--- (change
> > subject to 'what goes on newsgroups'?), but it's not clear from fact
> > what assumption who has made.
>
> Since you did not elaborate on what your efforts were and the extent
> they were undesirable (certainly useful info from someone honestly
> interested in a helpful answer), I assumed you had made none.

I agree. To one of my friends, there's plenty of information in the
context that isn't a newsgroup. So I'll state more about my
background.

Classes and modules are really similar. In Python they're really
*really* similar.

Actually, at this point, that observation may have more of a
subjective component than I'm used to asserting. I pause here for
corroboration and others' perspectives. Aren't they?

D'Arcy J.M. Cain

3/5/2008 9:51:00 PM

0

On Wed, 5 Mar 2008 13:38:59 -0800 (PST)
Mike Driscoll <kyosohma@gmail.com> wrote:
> On Mar 5, 12:50 pm, castiro...@gmail.com wrote:

I'm not sure why you change the address like this but could you please
include the full address. Those of us who identify the time wasters
would also like to drop the responses to their posts and changing the
address makes this impossible.

--
D'Arcy J.M. Cain <darcy@druid.net> | Democracy is three wolves
http://www.druid.... | and a sheep voting on
+1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner.

Steven D'Aprano

3/5/2008 9:58:00 PM

0

On Wed, 05 Mar 2008 10:50:12 -0800, castironpi wrote:

> What is a class that is not a module?

Er, all of them?

I'm curious what classes you think are modules.


--
Steven

Mike Driscoll

3/5/2008 10:00:00 PM

0

On Mar 5, 3:51 pm, "D'Arcy J.M. Cain" <da...@druid.net> wrote:
> On Wed, 5 Mar 2008 13:38:59 -0800 (PST)
>
> Mike Driscoll <kyoso...@gmail.com> wrote:
> > On Mar 5, 12:50 pm, castiro...@gmail.com wrote:
>
> I'm not sure why you change the address like this but could you please
> include the full address. Those of us who identify the time wasters
> would also like to drop the responses to their posts and changing the
> address makes this impossible.
>
> --
> D'Arcy J.M. Cain <da...@druid.net> | Democracy is three


What are you talking about? I didn't change the address at all. I'm
not even sure what you mean. Are you talking about the post subject
line (which I have never touched in any post)? If you're talking about
the OP's email address, that's Google's fault for cropping them.

Mike

Paul McGuire

3/5/2008 10:14:00 PM

0

On Mar 5, 3:49 pm, castiro...@gmail.com wrote:
>
> Classes and modules are really similar.  In Python they're really
> *really* similar.
>
> Actually, at this point, that observation may have more of a
> subjective component than I'm used to asserting.  I pause here for
> corroboration and others' perspectives.  Aren't they?

If all you use classes for is for the purpose of a namespace, and all
of the methods in the class are just staticmethods, then you have used
a class to replicate a module, and they aren't just really, *really*
similar, they are the pretty much the same (at least BEHAVIORALLY
speaking).

But you can't do this:

import Zmodule
zobject = Zmodule()

If you are really using the OO model, and creating instances of
classes, then you *have* to use a class, a module wont cut it. I'd
say, the less you use a class as an instance factory, the more similar
that class is to a module.

And you can't do this:

class Zclass:

import Zclass

If Zclass is not defined in your local script, you *have* to know what
module it is in, as in:

from zpackage.zmodule import Zclass

I have seen modules compared to classes that implement a Singleton
pattern. In this case, a class is being used in an intentionally
degenerate way, such that it creates only one instance. When doing
this in Python, one has the choice of replicating the standard pattern
with a class, or more simply, just using a module. (Python's language/
object model also permits another option, usually referred to as the
Borg implementation, in which many Python names bind to many Python
instances, but all share the same underlying object state. But this
is tangential to your question.)

In general I would say the similarity is a behavioral one, an artifact
of the language implementation. Modules are for code packaging and
namespace definition, classes are for type definition and object
modeling.

For more discussions about how similar classes are to modules, you
might google for "Python singleton".

-- Paul

Aaron Brady

3/5/2008 10:17:00 PM

0

On Mar 5, 3:58 pm, Steven D'Aprano <st...@REMOVE-THIS-
cybersource.com.au> wrote:
> On Wed, 05 Mar 2008 10:50:12 -0800, castironpi wrote:
> > What is a class that is not a module?
>
> Er, all of them?
>
> I'm curious what classes you think are modules.
>
> --
> Steven

Thank you for your time in entertaining my questions so far.

Functions are first-class objects.
Modules are first-class objects.
Classes are first-class objects.

There's even a ModuleType in 'types'.

>>> set( dir(type('None',(),{})) )- set( dir( ModuleType ) )
{'__module__', '__weakref__'}

How superficial are the differences?