This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Clarify struct doc for format 's', when it is mentioned without numeric prefix
Type: Stage: resolved
Components: Versions: Python 3.2, Python 3.3, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: orsenthil, python-dev, terry.reedy
Priority: normal Keywords: patch

Created on 2011-03-07 18:29 by terry.reedy, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
zstruct.diff terry.reedy, 2011-03-07 18:30
Messages (7)
msg130275 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2011-03-07 18:29
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'
msg130277 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2011-03-07 18:30
patch
msg139924 - (view) Author: Senthil Kumaran (orsenthil) * (Python committer) Date: 2011-07-06 06:42
Is this not implicit? Do we really need this stmt? I am -0 on this. If you agree, you can close this issue.
msg139926 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2011-07-06 07:01
A default of 1 in not implicit for output formatting.
%s and {:s} mean however long needed, not %1s or {:1s}
msg139927 - (view) Author: Senthil Kumaran (orsenthil) * (Python committer) Date: 2011-07-06 07:41
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.
msg139964 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2011-07-07 01:44
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.
msg140522 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2011-07-17 09:32
New changeset 90cdf403132e by Senthil Kumaran in branch '3.2':
Fix closes Issue11436 - Minor clarification to struct documentation for 's' format character.
http://hg.python.org/cpython/rev/90cdf403132e
History
Date User Action Args
2022-04-11 14:57:14adminsetgithub: 55645
2011-07-17 09:32:24python-devsetstatus: open -> closed

nosy: + python-dev
messages: + msg140522

resolution: fixed
stage: resolved
2011-07-07 01:44:02terry.reedysetmessages: + msg139964
2011-07-06 07:41:38orsenthilsetmessages: + msg139927
2011-07-06 07:01:00terry.reedysetmessages: + msg139926
versions: - Python 3.1
2011-07-06 06:42:49orsenthilsetnosy: + orsenthil

messages: + msg139924
title: Clarify struct doc for format 's'. -> Clarify struct doc for format 's', when it is mentioned without numeric prefix
2011-03-07 18:30:34terry.reedysetfiles: + zstruct.diff

messages: + msg130277
keywords: + patch
2011-03-07 18:29:36terry.reedycreate