need an alternative to getattr()

Uffe Wassmann hadaqada at gmail.com
Mon Aug 7 11:37:39 EDT 2006


I think you would benefit from looking at the ConfigParser module.
I haven't tried it yet, but it looks like a nice interface for writing
and reading configuration files.

-Uffe.

On 7 Aug 2006 07:30:41 -0700, pranav.choudhary at gmail.com
<pranav.choudhary at gmail.com> wrote:
> Hi,
>
> AIM: I have a config file that contains configuration under headings
> like this:
>
> heading1:
> <configuration 1>
> <configuration 2>
> heading2:
> <configuration 1>
> <configuration 2>
> ...
> ...
>
> i parse this file to get heading1, heading2, etc and then i want to
> call heading1.process(), heading2.process(), etc.
> What i am trying to do is: (this is not the exact code, it just
> represents what i am trying to do)
>
> import heading1
> import heading2
> While True:
>    heading = get_next_heading(file_ptr) # This func will return
> "heading1", then "heading2"(on next call)
>    if heading = "":
>        break
>    getattr(heading, "process")(file_ptr) # The problem, as you would
> have noticed, is that the first
> # argument to getattr is a string!!
>
> Is there an alternatice to getattr() that will solve my problem, or is
> there another way to do it.
>
> -pranav
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>



More information about the Python-list mailing list