Confusion About Classes
mefjr75 at hotmail.com
Tue Dec 28 06:56:48 CET 2004
> 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'
> Basically..I'm confused on the proper use of 'self' in this type of
> situation, even after going through all these different tutorials.
> -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
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
... def __init__(self):
... def setData(self, data):
... self.data = data
... def getData(self):
... return self.data
... def nullData(self):
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
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
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