summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Svetlov <andrew.svetlov@gmail.com>2012-10-31 14:03:44 (GMT)
committerAndrew Svetlov <andrew.svetlov@gmail.com>2012-10-31 14:03:44 (GMT)
commit694f9ce3431d0fd918dbd4648c337f15d2fb1148 (patch)
treec90ac7df03d011709e1ad9069e859409d92c3400
parentf9c7c3641bc1b2f71806a9aebcb4925ed555db99 (diff)
parente1fa22a8ae02f3321a0878456173d68922e78804 (diff)
downloadcpython-694f9ce3431d0fd918dbd4648c337f15d2fb1148.zip
cpython-694f9ce3431d0fd918dbd4648c337f15d2fb1148.tar.gz
cpython-694f9ce3431d0fd918dbd4648c337f15d2fb1148.tar.bz2
Merge issue #16370: Mention Py_SetProgramName in example for very high level embedding.
-rw-r--r--Doc/extending/embedding.rst21
1 files changed, 13 insertions, 8 deletions
diff --git a/Doc/extending/embedding.rst b/Doc/extending/embedding.rst
index d004d24..ccbe681 100644
--- a/Doc/extending/embedding.rst
+++ b/Doc/extending/embedding.rst
@@ -58,6 +58,7 @@ perform some operation on a file. ::
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 @@ perform some operation on a file. ::
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: