By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,029 Members | 983 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,029 IT Pros & Developers. It's quick & easy.

classes and standard modules

P: n/a
I don't understand classes very well... maybe some day. Is it just me or
are they supposed to be difficult to understand? They make my head hurt.

Anyway, because I don't understand classes well, I avoid using them.
However, many modules in the standard library are implemented as
classes: sgmllib, HTMLParser, etc. Is it possible to use these modules
without getting into OO programming and inheritance and all the other
lofty, theoretical CS concepts that small script writers, like me, don't
really need?
Jul 18 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
On Thu, 16 Sep 2004 21:47:52 -0400, Brad Tilley wrote:
Anyway, because I don't understand classes well, I avoid using them.
However, many modules in the standard library are implemented as
classes: sgmllib, HTMLParser, etc. Is it possible to use these modules
without getting into OO programming and inheritance and all the other
lofty, theoretical CS concepts that small script writers, like me, don't
really need?


Yes.

Without further information it is hard to add anything to the examples
that accompany the various libraries.

A couple people may jump in here to describe classes again; I'm going to
instead suggest just using Python for a while and taking a crack at it
again later when you've used more Python. For some pragmatically-minded
types of people, it is much easier to describe how classes work when we
have something concrete to point at. Later on, post some code you're
wondering about and ask questions (as specific as possible) and we'll be
happy to help.
Jul 18 '05 #2

P: n/a
Brad Tilley wrote:
I don't understand classes very well... maybe some day. Is it just me or
are they supposed to be difficult to understand? They make my head hurt.
They're not really that hard. Classes are nothing more than
_templates_ for blobs of data with associated functions. When
you instantiate a class (i.e. create an instance) you just get
one of those blobs of data, matching the pattern defined by the
template. You can call those associated functions and they
already know how to work on the data in the blob.

If you have a C background, think of classes as being structs with
a bunch of functions that are designed to work with those structs.
Anyway, because I don't understand classes well, I avoid using them.
However, many modules in the standard library are implemented as
classes: sgmllib, HTMLParser, etc. Is it possible to use these modules
without getting into OO programming and inheritance and all the other
lofty, theoretical CS concepts that small script writers, like me, don't
really need?


Well, for any of those, you just create one of the blobs of data,
say like "server = smtplib.SMTP('myhost')", and now you have a blob
with the name "server". You want to call one of those functions?
Instead of passing the data in the argument list as you do with
regular functions, you use the syntactic sugar form that looks like
this: "server.sendmail(...)".

This description needs you to know about blobs of data and functions,
neither of which are very lofty or theoretical, I think. :)

-Peter
Jul 18 '05 #3

P: n/a
Brad Tilley wrote:
Is it possible to use these modules
without getting into OO programming and inheritance and all the other
lofty, theoretical CS concepts that small script writers, like me, don't
really need?


Theoretically yes, in practice no.

Istvan.
Jul 18 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.