0

I am using Python C API to connect to my python v2.7.2

As the title suggests, I am looking to use unicode string as key in my dictionary. I am aware that we can use unicode string as key in python dictionary. But how is that possible through Python C API.

int PyDict_SetItemString(PyObject *p, const char *key, PyObject *val)

we have the above for using the ascii values. Is there any way for it?

Thanks in advance.

1
  • I see you have asked 7 questions, but have not marked an accepted answer for any of them. If you ask a question, and someone sufficiently answers your question, then you should click the check-mark outline on the left side of the answer to mark it as "accepted". Commented Feb 9, 2015 at 19:34

1 Answer 1

1

Use

int PyDict_SetItem(PyObject *p, PyObject *key, PyObject *val)

and pass in a:

PyObject *PyUnicode_FromString(const char *u)

as the key

Sign up to request clarification or add additional context in comments.

2 Comments

So when i use PyObject* PyDict_GetItem(PyObject *p, PyObject *key) it will retrieve the same key as added above?
It will retrieve the same value as set above.

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.