using ctypes methods in python gives unexpected error

I'm pretty new to python and ctypes. I'm trying to accomplish a seemingly easy task but am getting unexpected results. I'm trying to pass a string to a c function so I'm using the c_char_p type but it's giving me an error message. To simply it, this is whats happening:

>>>from ctypes import *
>>>c_char_p("hello world") 
 Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: string or integer address expected instead of str instance

What's going on here?


ANSWERS:


In Python 3.x, the "text literal" is really a unicode object. You want to use the byte-string literal like b"byte-string literal"

>>> from ctypes import *
>>> c_char_p('hello world')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: string or integer address expected instead of str instance
>>> c_char_p(b'hello world')
c_char_p(b'hello world')
>>>


 MORE:


 ? How to handle wchar_t ** with python ctypes?
 ? referencing opaque types with python ctypes
 ? Python - Ctypes: How to pass Void* as argument
 ? How to use malloc and free with python ctypes?
 ? Working with ctypes return values
 ? UnicodeEncodeError when a space is used
 ? UnicodeEncodeError when a space is used
 ? UnicodeEncodeError when a space is used
 ? UnicodeEncodeError when using the compile function
 ? Special characters in Python strings when writing code