← 输入框|bugs.python.org|刷新

➜

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
标题: Clarify struct doc for format 's', when it is mentioned without numeric prefix
类型: Stage: resolved
Components: Versions: Python 3.2, Python 3.3, Python 2.7
process
状态: closed Resolution: fixed
Dependencies: 后续:
分配给: 抄送列表: orsenthil, python-dev, terry.reedy
优先级: normal 关键字: 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.

文件
文件名 上传时间 Description 编辑
zstruct.diff terry.reedy, 2011-03-07 18:30
Messages (7)
msg130275 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) 日期: 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) 日期: 2011-03-07 18:30
patch
msg139924 - (view) Author: Senthil Kumaran (orsenthil) * (Python committer) 日期: 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) 日期: 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) 日期: 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) 日期: 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) 日期: 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
历史
日期 用户 动作 参数
2022-04-11 14:57:14admin修改github: 55645
2011-07-17 09:32:24python-dev修改状态: open -> closed

抄送: + python-dev
消息: + msg140522

resolution: fixed
stage: resolved
2011-07-07 01:44:02terry.reedy修改消息: + msg139964
2011-07-06 07:41:38orsenthil修改消息: + msg139927
2011-07-06 07:01:00terry.reedy修改消息: + msg139926
versions: - Python 3.1
2011-07-06 06:42:49orsenthil修改抄送: + orsenthil

消息: + msg139924
标题: 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.reedy修改文件: + zstruct.diff

消息: + msg130277
keywords: + patch
2011-03-07 18:29:36terry.reedy创建