[docs] documentation bug in "embedding python"

Zachary Ware zachary.ware+pydocs at gmail.com
Fri Jan 31 21:39:06 CET 2014


Hi Riccardo,

On Tue, Dec 31, 2013 at 11:15 AM, Riccardo Rossi <rrossi at cimne.upc.edu> wrote:
> Dear developers,
>
> i tried the simplest possible embedding described in
>
> http://docs.python.org/3.3/extending/embedding.html#very-high-level-embedding
>
> using python3.
>
> the example code does not compile (from c++) with error:
> /home/riccardo/scratch/kratospy3/embedded_python/krun_main.cpp: In function
> ‘int main(int, char**)’:
> /home/riccardo/scratch/kratospy3/embedded_python/krun_main.cpp:8:28: error:
> cannot convert ‘char*’ to ‘wchar_t*’ for argument ‘1’ to ‘void
> Py_SetProgramName(wchar_t*)’
>    Py_SetProgramName(argv[0]);  /* optional but recommended */
>                             ^
>
>
> what is the correct version for this?
>
> if i define the main with wchar_t instead of char i get a warning...

Instead of changing the return type of main, try casting argv[0] to
wchar_t *, like so:

#include <Python.h>

int
main(int argc, char *argv[])
{
  Py_SetProgramName((wchar_t *)argv[0]);  /* optional but recommended */
  Py_Initialize();
  PyRun_SimpleString("from time import time,ctime\n"
                     "print('Today is', ctime(time()))\n");
  Py_Finalize();
  return 0;
}

This seems to work using MSVC++ 2010; if it works for you as well, I
will change the documentation page to match.

Thanks for the report!

-- 
Zach


More information about the docs mailing list