On 06May2021 03:43, Dennis Sweeney <[email protected]> wrote:
>Maybe I'm missing something, but why do you need the SimpleNamespace at all? 
>Why not make your own mapping as in
>
>    class StringMapper:
>        ...
>        def __getitem__(self, s):
>            # Whatever arbitrary behavior you want
>            # Process suffixes, etc here, for example:
>            if s.endswith(".lc"):
>                return self.wrapped[s.removesuffix(".lc")].lower()
>            return self.wrapped[s]
>
>   format_string.format_map(StringMapper(whatever))
>
>Maybe then the data can just be data and this wrapper can handle all 
>the formatting conversions.

All this is somewhat orthoganal to adding more !foo things.

If we're not talking about extending the conversions, we should probably 
take this over to python-list, because the ":foo" stuff is just 
implementation.

That said, because my tags can have dots in their names and I want to be 
able to write:

    {tag.name.with.dot}

and this is accomplished with an elaborate SimpleNamespace subclass to 
make the .name.with.dot stuff work as attributes.  Just don't ask :-( 
Oh, you did :-)

Anyway, I may be shifting sideways per my recent ":foo" post, using a 
new class which is a magic view of the TagSet and a Formatter subclass 
which parses the field_names itself (thus grabbing the dotted 
identifier). Still a work in progress.

Cheers,
Cameron Simpson <[email protected]>
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/[email protected]/message/WTCYMJAHIRDGPJCS4UDZRBCIHOWKDTJ7/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to