Shriramana Sharma added the comment:
I came upon this too. In Python 2 it used to expect a one character string.
Apparently the same error message has been carried forward to Python 3 too,
though now the actual expected input is either a one character bytes type and
not a str type, or an int corresponding to the ord() value of that char.
Minimal demonstration:
$ python
Python 2.7.4 (default, Apr 19 2013, 18:28:01)
[GCC 4.7.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from ctypes import *
>>> class test ( Structure ) :
... _fields_ = [ ( "ch", c_char ) ]
...
>>> a = test()
>>> a.ch = ord('a')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: one character string expected
>>> a.ch = 'c'
>>> a.ch
'c'
>>>
$ python3
Python 3.3.1 (default, Apr 17 2013, 22:30:32)
[GCC 4.7.3] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from ctypes import *
>>> class test ( Structure ) :
... _fields_ = [ ( "ch", c_char ) ]
...
>>> a = test()
>>> a.ch = 'c'
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: one character string expected
>>> a.ch = b'c'
>>> a.ch
b'c'
>>> a.ch = ord('c')
>>> a.ch
b'c'
>>>
----------
nosy: +jamadagni
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue17991>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com