473,903 Members | 4,608 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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?
Jul 18 '05 #1
3 1602
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
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('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
Jul 18 '05 #3
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

26
29660
by: Joshua Beall | last post by:
Hi All, I remember reading that both nested classes and namespaces would be available in PHP5. I know that namespaces got canceled (much sadness...), however, I *thought* that nested classes were still an option. However, I am coming up dry looking for information on how to do this, and the most recent references I am able to find to nested classes in PHP are dated 2003. And they all say the same thing: sorry, can't do that.
5
3428
by: Geoff Turner | last post by:
Hi all, I have 3 questions regarding classes. 1:- If I have a class, Class1, how do I get Class2 to inherit class1? 2:- Assuming that the above is possible, if Class1 contains a function, Funct1, what scope keyword do I need so that Funct1 is only visible to derived classes? 3:- Can the same be done with constants and varibles? I'm using VB6 by the way...
3
1650
by: Dan Rawson | last post by:
I have several simple classes which need to us "standard" modules like os and sys A class might look like: # --------- MyClass.py ----------------------- class MyClass: def __init__ (self): self.data = '' self.data2 = 'mydata'
1
1226
by: John Abel | last post by:
A while back, I saw a thread asking if the standard lib modules would be modified to use the new logging module, and it got me thinking. As the new-style classes will be default for 2.4, will the standard lib modules be modified accordingly? Thanks John
16
2077
by: Simon Wittber | last post by:
I've noticed that a few ASPN cookbook recipes, which are recent additions, use classic classes. I've also noticed classic classes are used in many places in the standard library. I've been using new-style classes since Python 2.2, and am suprised people are still using the classic classes. Is there a legitimate use for classic classes that I am not aware of?
2
2445
by: F. Petitjean | last post by:
I have written a script to find the modules which export the largest number of names. The gc.getreferrers(*objs) function gives also an idea of the dependencies between the modules. The code (statsmod.py) : #!/usr/bin/env python # -*- coding: latin-1 -*- """
11
1490
by: John Salerno | last post by:
From my brief experience with C#, I learned that it was pretty standard practice to put each class in a separate file. I assume this is a benefit of a compiled language that the files can then be grouped together. What I'm wondering is how is this normally handled in Python? Is it normal for classes to be put in separate modules? It seems like this can get out of hand, since modules are separate from one another and not compiled...
5
1663
by: Alex | last post by:
Hi, this is my first mail to the list so please correct me if Ive done anything wrong. What Im trying to figure out is a good way to organise my code. One class per .py file is a system I like, keeps stuff apart. If I do that, I usually name the .py file to the same as the class in it. File: Foo.py *********************** class Foo:
173
5779
by: Zytan | last post by:
I've read the docs on this, but one thing was left unclear. It seems as though a Module does not have to be fully qualified. Is this the case? I have source that apparently shows this. Are modules left-over from VB6, and not much used anymore? It seems that it is better to require Imports or use fully qualified names for functions in other classes/modules, but a Module doesn't require this, cluttering the global namespace. It seems...
0
9853
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11293
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10882
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10989
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10504
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9692
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
8057
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7215
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
3
3327
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.