classes and standard modules

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Brad Tilley

    #1

    classes and standard modules

    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?
  • Jeremy Bowers

    #2
    Re: classes and standard modules

    On Thu, 16 Sep 2004 21:47:52 -0400, Brad Tilley wrote:[color=blue]
    > 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?[/color]

    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.

    Comment

    • phansen

      #3
      Re: classes and standard modules

      Brad Tilley wrote:[color=blue]
      > 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.[/color]

      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.
      [color=blue]
      > 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?[/color]

      Well, for any of those, you just create one of the blobs of data,
      say like "server = smtplib.SMTP('m yhost')", 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.sendmai l(...)".

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

      -Peter

      Comment

      • Istvan Albert

        #4
        Re: classes and standard modules

        Brad Tilley wrote:
        [color=blue]
        > 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?[/color]

        Theoretically yes, in practice no.

        Istvan.

        Comment

        Working...