0

I tried to use C char pointer datatype in python 3.3. I used following code:

    from ctypes import *

    firstname = c_char_p("I am a noob programmer".encode("utf-8"))
    print(firstname.value)

My desired output was

    I am a noob programmer

but what I got was

    b'I am a noob programmer'

I am following a tutorial made for python 2.6. I used "ascii" as the parameter for encode function. And also tried the "bytes()" instead of encode. But no difference at either time.Why don't I get my desired output? and How can I get the output as desired.

Please anybody help me to understand..

1
  • 3
    The output is correct for Python 3. Use Python 2.6 if you want to see the same output as the tutorial. Commented Apr 9, 2013 at 13:15

1 Answer 1

1

In Python 3 you need to decode it back to str if you want it to behave like str.

print(firstname.value.decode("utf-8"))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.