• "Invalid literal for int() with base 10": is it really a literal?

    From Roel Schroeven@21:1/5 to All on Fri May 26 09:55:16 2023
    Kevin M. Wilson's post "Invalid literal for int() with base 10?" got me thinking about the use of the word "literal" in that message. Is it
    correct to use "literal" in that context? It's correct in something like
    this:

    int('invalid')
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    ValueError: invalid literal for int() with base 10: 'invalid'

    But something like this generates the same message:

    int(input())
    hello
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    ValueError: invalid literal for int() with base 10: 'hello'

    In cases like this there is no literal in sight.

    I'm thinking it would be more correct to use the term 'value' here:
    ValueError: invalid value for int() with base 10: 'hello'
    Does my reasoning make sense?

    --
    "I love science, and it pains me to think that to so many are terrified
    of the subject or feel that choosing science means you cannot also
    choose compassion, or the arts, or be awed by nature. Science is not
    meant to cure us of mystery, but to reinvent and reinvigorate it."
    -- Robert Sapolsky

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Roel Schroeven@21:1/5 to All on Fri May 26 10:53:03 2023
    Op 26/05/2023 om 10:29 schreef Chris Angelico:
    However, if you want to change the wording, I'd be more inclined to synchronize it with float():

    float("a")
    Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    ValueError: could not convert string to float: 'a'

    I was looking for other ValueError-generating functions to find
    potentially better wording, and I somehow failed to think of float(), so
    thank you for mentioning it :) The ones I could think of were math
    functions like math.sqrt(); they give "ValueError: math domain error"
    which is rather less user friendly.

    --
    "'How to Stop Worrying and Learn to Love the Internet':
    1) everything that’s already in the world when you’re born is just
    normal;
    2) anything that gets invented between then and before you turn
    thirty is incredibly exciting and creative and with any luck you can
    make a career out of it;
    3) anything that gets invented after you’re thirty is against the
    natural order of things and the beginning of the end of civilisation
    as we know it until it’s been around for about ten years when it
    gradually turns out to be alright really.
    Apply this list to movies, rock music, word processors and mobile
    phones to work out how old you are."
    -- Douglas Adams

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Chris Angelico@21:1/5 to Roel Schroeven on Fri May 26 18:29:58 2023
    On Fri, 26 May 2023 at 17:56, Roel Schroeven <roel@roelschroeven.net> wrote:

    Kevin M. Wilson's post "Invalid literal for int() with base 10?" got me thinking about the use of the word "literal" in that message. Is it
    correct to use "literal" in that context? It's correct in something like this:

    int('invalid')
    Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    ValueError: invalid literal for int() with base 10: 'invalid'

    But something like this generates the same message:

    int(input())
    hello
    Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    ValueError: invalid literal for int() with base 10: 'hello'

    In cases like this there is no literal in sight.

    I'm thinking it would be more correct to use the term 'value' here: ValueError: invalid value for int() with base 10: 'hello'
    Does my reasoning make sense?


    It's a ValueError, so the problem is with the value. I suppose
    "invalid notation" might work, but since the definition of what's
    acceptable to the int() constructor is the same as for a Python
    literal, it's not wrong to use that word.

    However, if you want to change the wording, I'd be more inclined to
    synchronize it with float():

    float("a")
    Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    ValueError: could not convert string to float: 'a'

    ChrisA

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From MRAB@21:1/5 to Chris Angelico on Fri May 26 16:58:31 2023
    On 2023-05-26 09:29, Chris Angelico wrote:
    On Fri, 26 May 2023 at 17:56, Roel Schroeven <roel@roelschroeven.net> wrote:

    Kevin M. Wilson's post "Invalid literal for int() with base 10?" got me
    thinking about the use of the word "literal" in that message. Is it
    correct to use "literal" in that context? It's correct in something like
    this:

    int('invalid')
    Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    ValueError: invalid literal for int() with base 10: 'invalid'

    But something like this generates the same message:

    int(input())
    hello
    Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    ValueError: invalid literal for int() with base 10: 'hello'

    In cases like this there is no literal in sight.

    I'm thinking it would be more correct to use the term 'value' here:
    ValueError: invalid value for int() with base 10: 'hello'
    Does my reasoning make sense?


    It's a ValueError, so the problem is with the value. I suppose
    "invalid notation" might work, but since the definition of what's
    acceptable to the int() constructor is the same as for a Python
    literal, it's not wrong to use that word.

    However, if you want to change the wording, I'd be more inclined to synchronize it with float():

    float("a")
    Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    ValueError: could not convert string to float: 'a'

    You still need to mention the base because:

    int('y', 36)
    34

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From avi.e.gross@gmail.com@21:1/5 to All on Fri May 26 12:22:57 2023
    Roel,

    In order for the code to provide different error messages, it needs a way to differentiate between circumstances.

    As far as the int() function is concerned, it sees a string of characters and has no clue where they came from. In Python, int(input()) just runs input() first and creates a string and then passes it along to int().

    You can of course argue there are ways to phrase an error message that may be less technicalese.

    -----Original Message-----
    From: Python-list <python-list-bounces+avi.e.gross=gmail.com@python.org> On Behalf Of Roel Schroeven
    Sent: Friday, May 26, 2023 3:55 AM
    To: python-list@python.org
    Subject: "Invalid literal for int() with base 10": is it really a literal?

    Kevin M. Wilson's post "Invalid literal for int() with base 10?" got me thinking about the use of the word "literal" in that message. Is it
    correct to use "literal" in that context? It's correct in something like
    this:

    int('invalid')
    Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    ValueError: invalid literal for int() with base 10: 'invalid'

    But something like this generates the same message:

    int(input())
    hello
    Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    ValueError: invalid literal for int() with base 10: 'hello'

    In cases like this there is no literal in sight.

    I'm thinking it would be more correct to use the term 'value' here: ValueError: invalid value for int() with base 10: 'hello'
    Does my reasoning make sense?

    --
    "I love science, and it pains me to think that to so many are terrified
    of the subject or feel that choosing science means you cannot also
    choose compassion, or the arts, or be awed by nature. Science is not
    meant to cure us of mystery, but to reinvent and reinvigorate it."
    -- Robert Sapolsky

    --
    https://mail.python.org/mailman/listinfo/python-list

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Dieter Maurer@21:1/5 to Chris Angelico on Sat May 27 06:29:14 2023
    Chris Angelico wrote at 2023-5-26 18:29 +1000:
    ...
    However, if you want to change the wording, I'd be more inclined to >synchronize it with float():

    float("a")
    Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    ValueError: could not convert string to float: 'a'

    +1

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From alpha edge@21:1/5 to Dieter Maurer on Fri May 26 23:55:14 2023
    On Saturday, 27 May 2023 at 10:41:19 UTC+5:30, Dieter Maurer wrote:
    Chris Angelico wrote at 2023-5-26 18:29 +1000:
    ...
    However, if you want to change the wording, I'd be more inclined to >synchronize it with float():

    float("a")
    Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    ValueError: could not convert string to float: 'a'
    +1


    Hey Everyone Axel This Side, I m Real Estate Consultant as an Profession in a company called Alpha Edge Infratech
    Visit Our Site for More Info https://alphaedgeinfratech.com/property/signature-global-sco/ https://alphaedgeinfratech.com/property/rof-insignia-park-2/ https://geetanjalihomestate.co.in/mapsko-aspr-hills https://geetanjalihomestate.co.in/m3m-sco-plots-sector-114-gurgaon https://geetanjalihomestate.co.in/rof-insignia-park-2

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)