[Python-checkins] cpython (merge 3.2 -> 3.3): Merge issue #16370: Mention Py_SetProgramName in example for very high level

andrew.svetlov python-checkins at python.org
Wed Oct 31 15:04:39 CET 2012


http://hg.python.org/cpython/rev/b6a5f54e0a34
changeset:   80091:b6a5f54e0a34
branch:      3.3
parent:      80087:b6f302dfc5eb
parent:      80090:4c35f5ec6acf
user:        Andrew Svetlov <andrew.svetlov at gmail.com>
date:        Wed Oct 31 16:03:44 2012 +0200
summary:
  Merge issue #16370: Mention Py_SetProgramName in example for very high level embedding.

files:
  Doc/extending/embedding.rst |  21 +++++++++++++--------
  1 files changed, 13 insertions(+), 8 deletions(-)


diff --git a/Doc/extending/embedding.rst b/Doc/extending/embedding.rst
--- a/Doc/extending/embedding.rst
+++ b/Doc/extending/embedding.rst
@@ -58,6 +58,7 @@
    int
    main(int argc, char *argv[])
    {
+     Py_SetProgramName(argv[0]);  /* optional but recommended */
      Py_Initialize();
      PyRun_SimpleString("from time import time,ctime\n"
                         "print('Today is', ctime(time()))\n");
@@ -65,14 +66,18 @@
      return 0;
    }
 
-The above code first initializes the Python interpreter with
-:c:func:`Py_Initialize`, followed by the execution of a hard-coded Python script
-that print the date and time.  Afterwards, the :c:func:`Py_Finalize` call shuts
-the interpreter down, followed by the end of the program.  In a real program,
-you may want to get the Python script from another source, perhaps a text-editor
-routine, a file, or a database.  Getting the Python code from a file can better
-be done by using the :c:func:`PyRun_SimpleFile` function, which saves you the
-trouble of allocating memory space and loading the file contents.
+Function :c:func:`Py_SetProgramName` should be called before
+:c:func:`Py_Initialize` to inform the interpreter about paths to
+Python run-time libraries.  Next initialize the Python interpreter
+with :c:func:`Py_Initialize`, followed by the execution of a
+hard-coded Python script that prints the date and time.  Afterwards,
+the :c:func:`Py_Finalize` call shuts the interpreter down, followed by
+the end of the program.  In a real program, you may want to get the
+Python script from another source, perhaps a text-editor routine, a
+file, or a database.  Getting the Python code from a file can better
+be done by using the :c:func:`PyRun_SimpleFile` function, which saves
+you the trouble of allocating memory space and loading the file
+contents.
 
 
 .. _lower-level-embedding:

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list