Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 694f9ce

Browse files
committed
Merge issue #16370: Mention Py_SetProgramName in example for very high level embedding.
2 parents f9c7c36 + e1fa22a commit 694f9ce

1 file changed

Lines changed: 13 additions & 8 deletions

File tree

Doc/extending/embedding.rst

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,21 +58,26 @@ perform some operation on a file. ::
5858
int
5959
main(int argc, char *argv[])
6060
{
61+
Py_SetProgramName(argv[0]); /* optional but recommended */
6162
Py_Initialize();
6263
PyRun_SimpleString("from time import time,ctime\n"
6364
"print('Today is', ctime(time()))\n");
6465
Py_Finalize();
6566
return 0;
6667
}
6768

68-
The above code first initializes the Python interpreter with
69-
:c:func:`Py_Initialize`, followed by the execution of a hard-coded Python script
70-
that print the date and time. Afterwards, the :c:func:`Py_Finalize` call shuts
71-
the interpreter down, followed by the end of the program. In a real program,
72-
you may want to get the Python script from another source, perhaps a text-editor
73-
routine, a file, or a database. Getting the Python code from a file can better
74-
be done by using the :c:func:`PyRun_SimpleFile` function, which saves you the
75-
trouble of allocating memory space and loading the file contents.
69+
Function :c:func:`Py_SetProgramName` should be called before
70+
:c:func:`Py_Initialize` to inform the interpreter about paths to
71+
Python run-time libraries. Next initialize the Python interpreter
72+
with :c:func:`Py_Initialize`, followed by the execution of a
73+
hard-coded Python script that prints the date and time. Afterwards,
74+
the :c:func:`Py_Finalize` call shuts the interpreter down, followed by
75+
the end of the program. In a real program, you may want to get the
76+
Python script from another source, perhaps a text-editor routine, a
77+
file, or a database. Getting the Python code from a file can better
78+
be done by using the :c:func:`PyRun_SimpleFile` function, which saves
79+
you the trouble of allocating memory space and loading the file
80+
contents.
7681

7782

7883
.. _lower-level-embedding:

0 commit comments

Comments
 (0)