On Sat, Oct 2, 2021 at 12:19 PM Debashish Palit <dpali...@outlook.com> wrote: > > The method need not take care of every variation. Currently there is no > method to check for a float in a string even without formatting. str.numeric > or str.decimal don't work. str.isfloat would test unformatted strings for > floats or ints just like the functions int() and float() convert strings of > numbers. > > As for the use cases, I can think of 2: > > 1. When accepting user input with the input() function, you may get integers > and not floats. If you just convert the strings to floats, you will get the > result of a calculation as a float. Here the type of the input needs to be > preserved. > 2. A case that may come up often is passing numbers as strings to an instance > method. After converting the number to a float, you may want to output the > value in a repr method. Saving the precise type would help. > > The parse_value function would work as well but str.isfloat is more inline > with the current string methods. Also string methods return either a boolean > or a string and parse_value returns a number and is suited to a personal > library. > > Why do you call it 'bloat'? It is just one function with a few lines of code. > Other languages like Haskell have much bigger libraries.
Because your version of the function is slightly different from other people's versions. Making it part of the core language would require that it be right for everyone. Instead, just have the simple version in your own code, and it can be perfect for your usage. ChrisA _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/XAV5T27NYA226ME4BDZARUZJV7R5XWSM/ Code of Conduct: http://python.org/psf/codeofconduct/