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.

Author rrt
Recipients docs@python, rrt
Date 2019-07-12.07:40:49
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1562917249.5.0.829310494906.issue37571@roundup.psfhosted.org>
In-reply-to
Content
The CTypes documentation has this example:

>>> s = c_char_p()
>>> s.value = "abc def ghi"
>>> s.value
'abc def ghi'
>>> s.value is s.value
False
>>>

It appears not to have been updated since Python 2: in Python 3, you can't assign a str to a c_char_p. If one tries the example code above, one gets:

>>> s = c_char_p()
>>> s.value = "abc def ghi"
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: bytes or integer address expected instead of str instance

Using a bytes works:

>>> s = c_char_p()
>>> s.value = b"abc def ghi"
>>> s.value
b'abc def ghi'
>>> s.value is s.value
False
>>>

Hence adding the two "b"s is an obvious fix.

Note that the similar example with c_wchar_p does work fine with str.
History
Date User Action Args
2019-07-12 07:40:49rrtsetrecipients: + rrt, docs@python
2019-07-12 07:40:49rrtsetmessageid: <1562917249.5.0.829310494906.issue37571@roundup.psfhosted.org>
2019-07-12 07:40:49rrtlinkissue37571 messages
2019-07-12 07:40:49rrtcreate