← 输入框|github.com|刷新
Skip to content

Clarify struct doc for format 's', when it is mentioned without numeric prefix #55645

Closed

Description

@terryjreedy
BPO 11436
Nosy @terryjreedy, @orsenthil
Files
  • zstruct.diff
  • 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 2011-07-17.09:32:24.973>
    created_at = <Date 2011-03-07.18:29:36.358>
    labels = []
    title = "Clarify struct doc for format 's', when it is mentioned without numeric prefix"
    updated_at = <Date 2011-07-17.09:32:24.971>
    user = 'https://github.com/terryjreedy'

    bugs.python.org fields:

    activity = <Date 2011-07-17.09:32:24.971>
    actor = 'python-dev'
    assignee = 'none'
    closed = True
    closed_date = <Date 2011-07-17.09:32:24.973>
    closer = 'python-dev'
    components = []
    creation = <Date 2011-03-07.18:29:36.358>
    creator = 'terry.reedy'
    dependencies = []
    files = ['21035']
    hgrepos = []
    issue_num = 11436
    keywords = ['patch']
    message_count = 7.0
    messages = ['130275', '130277', '139924', '139926', '139927', '139964', '140522']
    nosy_count = 3.0
    nosy_names = ['terry.reedy', 'orsenthil', 'python-dev']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue11436'
    versions = ['Python 2.7', 'Python 3.2', 'Python 3.3']

    Activity

    1. terryjreedy commented on Mar 7, 2011

      @terryjreedy
      MemberAuthor

      The struct doc does not specify the meaning of 's', without a count. The attached patch adds the sentence:

      If a count is not given, it defaults to 1; 's' means the same as '1s'.

      (Until I experimented, I had thought no count meant indefinite length).

      >>> struct.pack('sss', b'', b'a', b'ab')
      b'\x00aa'
      >>> struct.pack('1s1s1s', b'', b'a', b'ab')
      b'\x00aa'
    2. terryjreedy commented on Mar 7, 2011

      @terryjreedy
      MemberAuthor

      patch

    3. orsenthil commented on Jul 6, 2011

      @orsenthil
      Member

      Is this not implicit? Do we really need this stmt? I am -0 on this. If you agree, you can close this issue.

    4. changed the title [-]Clarify struct doc for format 's'.[/-] [+]Clarify struct doc for format 's', when it is mentioned without numeric prefix[/+] on Jul 6, 2011
    5. terryjreedy commented on Jul 6, 2011

      @terryjreedy
      MemberAuthor

      A default of 1 in not implicit for output formatting.
      %s and {:s} mean however long needed, not %1s or {:1s}

    6. orsenthil commented on Jul 6, 2011

      @orsenthil
      Member

      That is for the string formatting character, correct?

      In this issue, we are talking about format character for struct and
      not just 's' but 'c','h','b','i' all without numeric prefix imply
      single value.

    7. terryjreedy commented on Jul 7, 2011

      @terryjreedy
      MemberAuthor

      Those others field types have a standard or system-dependent fixed size and a number is an optional repeat count. Format 's' is always a single field because number prefix for that is special -- a field size.

      "For the 's' format character, the count is interpreted as the length of the bytes, not a repeat count like for the other format characters; for example, '10s' means a single 10-byte string, while '10c' means 10 characters. "

      I happen to think is could use a few more words of special explanation. Looking again, I think ", which defaults to 1" after the first 'count' above, would be sufficient. We nearly always docucument defaults.

    8. python-dev commented on Jul 17, 2011

      python-devmannequin
      Mannequin

      New changeset 90cdf403132e by Senthil Kumaran in branch '3.2':
      Fix closes bpo-11436 - Minor clarification to struct documentation for 's' format character.
      http://hg.python.org/cpython/rev/90cdf403132e

    9. 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

      No labels
      No labels

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions