Message347725
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. |
|
Date |
User |
Action |
Args |
2019-07-12 07:40:49 | rrt | set | recipients:
+ rrt, docs@python |
2019-07-12 07:40:49 | rrt | set | messageid: <1562917249.5.0.829310494906.issue37571@roundup.psfhosted.org> |
2019-07-12 07:40:49 | rrt | link | issue37571 messages |
2019-07-12 07:40:49 | rrt | create | |
|