[Tutor] I Give Up.
Python
python at venix.com
Sat Jun 17 23:56:03 CEST 2006
On Sat, 2006-06-17 at 16:44 -0400, Brian Gustin wrote:
> I have had it. I give up.
>
> Python's documentation sucks beyond belief.
A lot of it is excellent. The ConfigParser, that you are complaining
about is woefully short on examples and does not make clear that you
*must read* the other sections.
>
> all I want to do is parse a *SIMPLE* config file of name = value pairs
> and have python objects named by the name holding the value signified by
> value , and I want it to be able to work *WITHOUT* someone having to
> download and install additional modules, etc, so I looked up ConfigParser
>
> OK, cool, at least it appears capable. however:
> *section of code relevant to issue*
>
> from ConfigParser import SafeConfigParser
> cfg = SafeConfigParser("/etc/local-config/myconfig.cfg")
The initialization is your default values!
cfg = SafeConfigParser()
cfg.read("/etc/local-config/myconfig.cfg")
> mystuff = cfg.items("Parameters",)#kept giving me an exception that 2
> values required
> print mystuff
>>> help(cfg.items)
Help on method items in module ConfigParser:
items(self, section, raw=False, vars=None) method of
ConfigParser.SafeConfigParser instance
Return a list of tuples with (name, value) for each option
in the section.
All % interpolations are expanded in the return values, based on the
defaults passed into the constructor, unless the optional argument
`raw' is true. Additional substitutions may be provided using the
`vars' argument, which must be a dictionary whose contents overrides
any pre-existing defaults.
The section DEFAULT is special.
>
>
> [brian at NixServer python_snips]$ ./pymon.py
> Traceback (most recent call last):
> File "./pymon.py", line 20, in ?
> main()
> File "./pymon.py", line 15, in main
> myname = cfg.items("Parameters",)
> File "/usr/lib/python2.3/ConfigParser.py", line 532, in items
> d = self._defaults.copy()
> OK.. so items doesnt appear to work (the above is my tenth attempt to
> get it working) So.. "RTSL!" (Read The Source, Luke) - I grokked
> /usr/lib/python2.3/ConfigParser.py" to have a look see at how it does
> what it does, and found additional stuff that isnt documented *AT ALL*
> .. So..
>
>
> [brian at NixServer python_snips]$ ./pymon.py
> Traceback (most recent call last):
> File "./pymon.py", line 20, in ?
> main()
> File "./pymon.py", line 15, in main
> myname = cfg.section()
> AttributeError: SafeConfigParser instance has no attribute 'section'
>
myname = cfg.sections()
^
Will work for you and provide a list of sections. You will need those
sections to feed into the items call.
> OK Obviously I have no clue how the heck this is all supposed to work,
> and I have wasted 3 hours of development time on this thing (it aint the
> first time I have had issues with Python's Documentation)
>
> Whatever. I give up..
No don't!
You are almost there.
>
> I'll just go write it in Perl. Maybe some day when Python actually has
> well structured documentation with *actual working code examples* I
> might take another look at trying to learn more of it, but at this
> point, time is money, and I can develop the same application in Perl
> (probably would have it *done* by now, it's really simple)..
I came to Python after Perl and lot's of other languages. I think
Python is better, but it helps to have someone to talk to when things
are going badly.
>
> I just needed to vent - I cannot believe how Python ever managed to get
> *anywhere* with the state of documentation at python.org
>
I liked the old layout better, but presumably you found this:
http://docs.python.org/lib/RawConfigParser-objects.html
> If you want an example of what I would call quality online documentation
> - need look no further than php.net (or dev.mysql.com) .. or even
> cpan.org (or heck, just run perldoc in commandline.. ) I tried pydoc..
> it just doesnt cut the mustard..
>
> OK..
> /end rant
>
> Now can someone explan how exactly (preferrably with an actual real
> world example) that I can read a configuration file in , say
> /etc/local-config/myconfig.cfg into my python script running in
> /usr/bin/localscripts , and able to actually use the names as variables
> (objects) with the configured values assigned to them?
>
> This drove me nuts the past couple hours, and truthfully, as much as I
> like python (I really LIKE python) .. the documentation sucks *SO* bad,
> I just cannot justify attempting to learn more and use it for more
> projects because of situations like this that do nothing but waste my time.
>
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
--
Lloyd Kvam
Venix Corp
More information about the Tutor
mailing list