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 jamadagni
Recipients Steven.Barker, amaury.forgeotdarc, jamadagni, meador.inge
Date 2013-06-02.14:10:55
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1370182255.52.0.890953198333.issue17991@psf.upfronthosting.co.za>
In-reply-to
Content
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'
>>>
History
Date User Action Args
2013-06-02 14:10:55jamadagnisetrecipients: + jamadagni, amaury.forgeotdarc, meador.inge, Steven.Barker
2013-06-02 14:10:55jamadagnisetmessageid: <1370182255.52.0.890953198333.issue17991@psf.upfronthosting.co.za>
2013-06-02 14:10:55jamadagnilinkissue17991 messages
2013-06-02 14:10:55jamadagnicreate