Confusion About Classes

M.E.Farmer mefjr75 at
Tue Dec 28 06:56:48 CET 2004

flamesrock wrote:
> 3) Can I create a configParser object and just call self.parser.set()
> inside the function without passing it as a parameter, or do I pass
> as a parameter and call it as parser.set (without the 'self'
> statement.)
> Basically..I'm confused on the proper use of 'self' in this type of
> situation, even after going through all these different tutorials.
> ideas?
> -thanks in advance\
Ok you have several problems that I see.
First you are having namespace difficulties.
I am not sure you 'get it' yet , but if you stay around long enough you
will ;)

The proper use of 'self' in a class is its namespace.
You *have* to pass 'self' to all member functions of a class sp the all
can have a reference to the namespace.
It makes it easy to pass data back and forth between functions in a
Below is an example of functions calling functions within a class and
setting attributes, maybe this will clear it up some
py>class bla:
...    def __init__(self):
...    def setData(self, data):
... = data
...    def getData(self):
...        return
...    def nullData(self):
...        self.setData(None)

Namespace is one of those crucial concepts you *must* master in python.
Do a search on google for python namespace, and read, and code, till
you get it. Master namespace if you have not already. Break out an
interpreter and hack away. Use dir() around your classes and functions
and 'see' for yourself what is in them. Do a search on this newsgroup
for namespace. This has been explained much better than I can.

Second if you haven't done it yet read up on configparser.
before implementing a universalconfigwriter/reader you need to know how
to find previously written sections and options , and add error
checking etc..
Especially note this page.
(Hint this will save you from many long boring hours reinventing all
this junk and avoiding some eval hack to get the stuff back to the
right type.)
If you think I am kidding note others in this newsgroup have been there
done that, not me of course, I never need documentation ;)

More information about the Python-list mailing list