try..except or type() or isinstance()?
Manfred Lotz
ml_news at posteo.de
Sun Aug 16 03:40:12 EDT 2020
On Sat, 15 Aug 2020 12:20:48 -0400
Dennis Lee Bieber <wlfraed at ix.netcom.com> wrote:
> On Sat, 15 Aug 2020 15:31:56 +0200, Manfred Lotz <ml_news at posteo.de>
> declaimed the following:
>
> >On Sat, 15 Aug 2020 11:47:03 +0200
> >Sibylle Koczian <nulla.epistola at web.de> wrote:
> >
>
> >> if the value comes from a file, isn't it a
> >> string in any case? A string that may be convertible to int or
> >> not? Or what sort of file do I overlook?
> >>
> >
> >In this case it is a TOML file.
>
> Based on https://en.wikipedia.org/wiki/TOML this means you
> need a parser...
> """
> In TOML the syntax determines the data types ("syntax typing")
> """
>
> String data is surrounded with " marks, numbers are not
> (though the example doesn't show if integers are treated differently
> from floating point), arrays/lists in [] with embedded comma ([] are
> also overloaded for section headers, with subsections using
> section.subsection naming), dates are some ugly creation, and looks
> like true/false are reserved values.
>
> However, as pointed out -- all data read from the file will
> be seen as a Python string data type. It is only after determining
> the TOML data type -- by examining the string itself -- that one can
> convert to internal format.
>
> Unfortunately, TOML is not compatible with INI -- for which
> Python already has a read/write module. But there is
> https://pypi.org/project/toml/
> (uses the same example file as Wikipedia) -- latest version was from
> May.
>
>
I use tomlkit as the toml package doesn't support quoted keys
sufficiently.
--
Manfred
More information about the Python-list
mailing list