Skip to content

Programming FAQ about "How do I convert a string to a number?" contains a typo #84520

Closed

Description

@Dominik1123
BPO 40340
Nosy @aeros, @caje731, @Dominik1123
PRs
  • bpo-40340 Separate examples within the same sentence clearly. #19688
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2020-04-25.06:33:42.992>
    created_at = <Date 2020-04-20.19:37:45.484>
    labels = ['type-feature', '3.8', '3.9', 'docs']
    title = 'Programming FAQ about "How do I convert a string to a number?" contains a typo'
    updated_at = <Date 2020-04-25.06:33:42.991>
    user = 'https://github.com/Dominik1123'

    bugs.python.org fields:

    activity = <Date 2020-04-25.06:33:42.991>
    actor = 'aeros'
    assignee = 'docs@python'
    closed = True
    closed_date = <Date 2020-04-25.06:33:42.992>
    closer = 'aeros'
    components = ['Documentation']
    creation = <Date 2020-04-20.19:37:45.484>
    creator = 'Dominik V.'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 40340
    keywords = ['patch']
    message_count = 5.0
    messages = ['366870', '366871', '366875', '367144', '367239']
    nosy_count = 5.0
    nosy_names = ['docs@python', 'python-dev', 'aeros', 'cajetan.rodrigues', 'Dominik V.']
    pr_nums = ['19688']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue40340'
    versions = ['Python 3.8', 'Python 3.9']

    Activity

    1. Dominik1123 commented on Apr 20, 2020

      Dominik1123mannequin
      MannequinAuthor

      The paragraph about How do I convert a string to a number? contains the following sentence:

      By default, these interpret the number as decimal, so that int('0144') == 144 and int('0x144') raises ValueError.

      The first part however doesn't raise an error. Most likely octal notation was meant, i.e. int('0o144') == 144.

      For consistency with the int('0x144') part one could also omit the equality comparison, i.e. just write int('0o144').

      In order to emphasize that the "and" is not part of the code (though this should be displayed by the browser) once could also write:

      [...] so that both int('0o144') and int('0x144') raise ValueError.

      (emphasis added)

    2. added
      docsDocumentation in the Doc dir
      type-featureA feature request or enhancement
      on Apr 20, 2020
    3. caje731 commented on Apr 20, 2020

      caje731mannequin
      Mannequin

      these interpret the number as decimal

      I'm no linguist, but I feel both expressions in the subordinate clause have their purposes, with respect to the the main clause:

      • int('0144') == 144 to show what works
      • int('0x144') to show what does not work

      I don't believe the octal notation was meant in the first example, as the equality wouldn't then hold, even if somehow the typecast worked (which it doesn't). The point was to positively reinforce the idea that the content of the string would be interpreted as a decimal. So something like int('000000144') == 144 would still hold True. Negative reinforcement is provided in the second example.

      But I agree that the sentence itself does not clearly separate the two examples, so I would suggest adding a comma after the first example, like so:

      By default, these interpret the number as decimal, so that int('0144') == 144, and int('0x144') raises ValueError.

    4. Dominik1123 commented on Apr 20, 2020

      Dominik1123mannequin
      MannequinAuthor

      Indeed, thanks for clarifying. It seems I misunderstood the example, and perhaps that calls for a better separation. What about adding

      By default, these interpret the number as decimal, so that int('0144') == 144 holds true and int('0x144') raises ValueError.

    5. caje731 commented on Apr 23, 2020

      caje731mannequin
      Mannequin

      Yes, I think that's acceptable.

    6. aeros commented on Apr 24, 2020

      @aeros
      Contributor

      New changeset 5aafa54 by Cajetan Rodrigues in branch 'master':
      bpo-40340: Separate examples more clearly in the programming FAQ (GH-19688)
      5aafa54

    7. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      3.8 (EOL)end of life3.9 (EOL)end of lifedocsDocumentation in the Doc dirtype-featureA feature request or enhancement

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions