Greetings,
Using Python 3.4.3
I have tried using these C functions to create the PyUnicode string and they all behave the same way.
I have the source for the C Python engine but I haven't figure it out yet.
Using Python 3.4.3
- I am creating a PyUnicode string from a C string.
- I am passing this string as a argument to a Python function from C.
- In the setter function I can print out parameter.
- When I assign the parameter to an array then print out the array the string value is corrupted.
- I've been referencing PEP 393
- Performing the same activity in purely Python prints out the string argument and array fine.
I have tried using these C functions to create the PyUnicode string and they all behave the same way.
Output:// C code to create a PyUnicode string and set it into a tuple
void SetParameter(PyObject * pTuple, const char * psValue, unsigned int uPosition) {
// PyObject * obj = PyUnicode_FromStringAndSize(psValue, strlen(psValue));
// PyObject * obj = _PyUnicode_FromASCII(psValue, strlen(psValue));
// PyObject * obj = PyUnicode_FromFormat("%s", psValue);
PyObject * obj = PyUnicode_FromKindAndData(PyUnicode_1BYTE_KIND, psValue, strlen(psValue));
PyTuple_SetItem(pTuple, uPosition, obj);
}
# Python 3 function receiving the tuple with a strings def configure(self, ip1, ip2, ip3): print ("configure[ip list]", ip1, ip2, ip3) self.string_args.append('--ip') self.string_args.append(ip1) self.string_args.append('--ip') self.string_args.append(ip2) self.string_args.append('--ip') self.string_args.append(ip3) print ("configure[self.string_args]", self.string_args)
Output:# Printed output when configure() is executed from C
configure[ip list] 127.0.0.1 127.0.0.1 127.0.0.1
configure [self.string_args] ['--ip', ''27.0.0.1', '--ip', "\"\\\"\\\\\\, '--ip', '"\\"\\\\\\"\\\\\\\\\\\\', '--ip', '"\\"\\\\\\"\\\\\\\\\\\\']
Output:# Printed output when configure() is executed from Python
$ ./Test.py
configure [ip list] 127.0.0.1 127.0.0.2 127.0.0.3
configure [self.string_args] ['--ip', '127.0.0.1', '--ip', '127.0.0.2', '--ip', '127.0.0.3']
Due to the difference in behavior I conclude that it is something about the way the C code creates the PyUnicode objects. Perhaps I need to create some other object type?I have the source for the C Python engine but I haven't figure it out yet.