[Python-ideas] Re: s?scanf [was: A string function idea]

2022-03-30 Thread Stephen J. Turnbull
Chris Angelico writes: > On Wed, 30 Mar 2022 at 15:11, Stephen J. Turnbull > wrote: > > The first argument [of scanf could] be any iterable of > > characters, and if an iterator it would leave the iteration > > pointer where it left off (eg, beginning of next line in 'sample' > > above). >

[Python-ideas] Re: s?scanf [was: A string function idea]

2022-03-30 Thread Chris Angelico
On Wed, 30 Mar 2022 at 18:09, Stephen J. Turnbull wrote: > > Chris Angelico writes: > > I don't think, for instance, that json.load() promises anything > > about where it leaves an iterable; in fact, I believe it simply > > reads everything into a string and then parses that. > > It would seem

[Python-ideas] Re: s?scanf [was: A string function idea]

2022-03-30 Thread Stéfane Fermigier
FYI, there is a “parse” library on PyPI: https://pypi.org/project/parse/ *Parse strings using a specification based on the Python format() syntax.* *parse() is the opposite of format()* (I haven’t used it myself, but I find the idea compelling, specially for people unfamiliar with regexes or C-s

[Python-ideas] Allow os.getenv to optionally convert result to boolean

2022-03-30 Thread Adrian Torres Justo
We've used a lot of boolean environment variables in a recent project I've been working on, this led us to create a wrapper to os.getenv that essentially converts the result to a boolean using distutils.util.strtobool if an optional kwarg to our wrapper is set to True. Would it be far-fetched to h

[Python-ideas] Re: Allow os.getenv to optionally convert result to boolean

2022-03-30 Thread Serhiy Storchaka
30.03.22 14:05, Adrian Torres Justo пише: We've used a lot of boolean environment variables in a recent project I've been working on, this led us to create a wrapper to os.getenv that essentially converts the result to a boolean using distutils.util.strtobool if an optional kwarg to our wrapper

[Python-ideas] Re: Syntax proposal of for..in..if in regular for loops

2022-03-30 Thread Jeff Edwards
As someone who has read the entirety of those thread and is not a core-dev but having some experience with breaking and non-breaking changes at scale, from my perspective: 1. This is a common syntax for an existing idea that is intuitive given other existing syntax (comprehensions) 2. This would i

[Python-ideas] Re: Allow os.getenv to optionally convert result to boolean

2022-03-30 Thread Adrian Torres Justo
> Why not use just to_bool(getenv(key))? We did use distutils.util.strtobool(os.getenv(key, default)) for a while, eventually we just built a helper that did the same because it's easier / more comfortable. > No. There would be hundreds different trivial implementations. Can you elaborate? Here'

[Python-ideas] Re: Allow os.getenv to optionally convert result to boolean

2022-03-30 Thread Jeff Edwards
There are many times where the variable ultimately isn’t defined by your software but by someone else’s, in which case something like an empty string maybe considered true or false (depending of if existence/emptiness is used for indicating the boolean value). So I think it’s important that it be

[Python-ideas] Re: Allow os.getenv to optionally convert result to boolean

2022-03-30 Thread Paul Moore
On Wed, 30 Mar 2022 at 15:39, Adrian Torres Justo wrote: > > Why not use just to_bool(getenv(key))? > > We did use distutils.util.strtobool(os.getenv(key, default)) for a while, > eventually we just built a helper that did the same because it's easier / > more comfortable. > > > No. There would b

[Python-ideas] Re: Allow os.getenv to optionally convert result to boolean

2022-03-30 Thread Adrian Torres Justo
Fair enough, thanks for the explanation On Wed, Mar 30, 2022 at 4:55 PM Paul Moore wrote: > On Wed, 30 Mar 2022 at 15:39, Adrian Torres Justo > wrote: > >> > Why not use just to_bool(getenv(key))? >> >> We did use distutils.util.strtobool(os.getenv(key, default)) for a while, >> eventually we j

[Python-ideas] Re: Allow os.getenv to optionally convert result to boolean

2022-03-30 Thread Eric V. Smith
On 3/30/2022 11:02 AM, Adrian Torres Justo wrote: Fair enough, thanks for the explanation ... There are a lot of ways to interpret "convert to bool" - should "yes" and "no" be converted? What about "1" and "0"? Or "001", or "-1"? What should happen to unrecognised values? What if

[Python-ideas] Re: s?scanf [was: A string function idea]

2022-03-30 Thread Christopher Barker
On Wed, Mar 30, 2022 at 1:50 AM Stéfane Fermigier wrote: > FYI, there is a “parse” library on PyPI: https://pypi.org/project/parse/ > > *Parse strings using a specification based on the Python format() syntax.* > > *parse() is the opposite of format()* > > (I haven’t used it myself, > Me neither

[Python-ideas] Re: s?scanf [was: A string function idea]

2022-03-30 Thread Christopher Barker
On Wed, Mar 30, 2022 at 1:24 AM Chris Angelico wrote: > The standard definition of JSON is that there is a > single value I believe that single value has to be either an array or an object. At least some sub-specifications call for that. But we’ve gotten quite sidetracked :-) -CHB -- Chris

[Python-ideas] Re: s?scanf [was: A string function idea]

2022-03-30 Thread Paul Moore
On Wed, 30 Mar 2022 at 17:58, Christopher Barker wrote: > > On Wed, Mar 30, 2022 at 1:50 AM Stéfane Fermigier wrote: >> >> FYI, there is a “parse” library on PyPI: https://pypi.org/project/parse/ >> >> Parse strings using a specification based on the Python format() syntax. >> >> parse() is the o

[Python-ideas] Re: s?scanf [was: A string function idea]

2022-03-30 Thread Ricky Teachey
parse is a great library! i've used it a lot. --- Ricky. "I've never met a Kentucky man who wasn't either thinking about going home or actually going home." - Happy Chandler On Wed, Mar 30, 2022 at 1:08 PM Paul Moore wrote: > On Wed, 30 Mar 2022 at 17:58, Christopher Barker > wrote: > > > >