Re: [Python-Dev] C code: %s vs %U
26.03.14 03:43, Ethan Furman написав(ла): %s is a string. %U is unicode? If so, then %s should only be used when it is certain the string in question has no unicode in it? %s is UTF-8 encoded string. ___ Python-Dev mailing list Python-Dev@python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com
Re: [Python-Dev] C code: %s vs %U
On Tue, 25 Mar 2014 18:43:30 -0700 Ethan Furman et...@stoneleaf.us wrote: %s is a string. %U is unicode? What is the context? ___ Python-Dev mailing list Python-Dev@python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com
Re: [Python-Dev] C code: %s vs %U
On Wed, 26 Mar 2014 11:48:44 +0100 Antoine Pitrou solip...@pitrou.net wrote: On Tue, 25 Mar 2014 18:43:30 -0700 Ethan Furman et...@stoneleaf.us wrote: %s is a string. %U is unicode? What is the context? Ok, I suppose it's PyUnicode_Format? :-) (I was initially thinking PyArg_ParseTuple, but it doesn't use %) Regards Antoine. ___ Python-Dev mailing list Python-Dev@python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com
Re: [Python-Dev] C code: %s vs %U
2014-03-26 12:02 GMT+01:00 Antoine Pitrou solip...@pitrou.net: Ok, I suppose it's PyUnicode_Format? :-) I don't think that PyUnicode_Format supports %U. For PyUnicode_FromFormatV(), %U expects a Python Unicode object, whereas %s expects a ASCII (or latin1?) encoded byte string const char*. For PyArg_ParseTuple, s accepts str and bytes and encodes str to UTF-8, whereas U expects str. Victor ___ Python-Dev mailing list Python-Dev@python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com
Re: [Python-Dev] C code: %s vs %U
[Assuming you are talking about PyUnicode_FromFormatV] %s is a string. No. %s is a char*; C does not have a string type. The string behind the pointer should be UTF-8 encoded; other encodings are tolerated through the replace error handler. %U is unicode? No. This is a PyObject* whose Python type is 'str' (i.e. an object for which PyUnicode_Check succeeds) If so, then %s should only be used when it is certain the string in question has no unicode in it? No. If you have a char*, use %s; using %U would crash. Regards, Martin ___ Python-Dev mailing list Python-Dev@python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com
Re: [Python-Dev] C code: %s vs %U
On 03/26/2014 03:48 AM, Antoine Pitrou wrote: On Tue, 25 Mar 2014 18:43:30 -0700 Ethan Furman et...@stoneleaf.us wrote: %s is a string. %U is unicode? What is the context? A patch I'm adapting has these lines: static PyObject* module_getattr(PyObject *m, PyObject *name) { char *mod_name_str; ... PyErr_Format(PyExc_AttributeError, module '%s' has no attribute '%U', mod_name_str, name); So it looks like %s is referring to a simple string, and %U is referring to a PyObject, but I was hoping for verification. -- ~Ethan~ ___ Python-Dev mailing list Python-Dev@python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com
Re: [Python-Dev] C code: %s vs %U
On 03/26/2014 06:22 AM, � wrote: [Assuming you are talking about PyUnicode_FromFormatV] %s is a string. No. %s is a char*; C does not have a string type. The string behind the pointer should be UTF-8 encoded; other encodings are tolerated through the replace error handler. %U is unicode? No. This is a PyObject* whose Python type is 'str' (i.e. an object for which PyUnicode_Check succeeds) If so, then %s should only be used when it is certain the string in question has no unicode in it? No. If you have a char*, use %s; using %U would crash. Many thanks! -- ~Ethan~ ___ Python-Dev mailing list Python-Dev@python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com
[Python-Dev] C code: %s vs %U
%s is a string. %U is unicode? If so, then %s should only be used when it is certain the string in question has no unicode in it? -- ~Ethan~ ___ Python-Dev mailing list Python-Dev@python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com