Initial commit of OpenSPARC T2 design and verification files.
[OpenSPARC-T2-DV] / tools / src / nas,5.n2.os.2 / lib / python / html / python / ext / high-level-embedding.html
CommitLineData
86530b38
AT
1<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
2<html>
3<head>
4<link rel="STYLESHEET" href="ext.css" type='text/css' />
5<link rel="SHORTCUT ICON" href="../icons/pyfav.png" type="image/png" />
6<link rel='start' href='../index.html' title='Python Documentation Index' />
7<link rel="first" href="ext.html" title='Extending and Embedding the Python Interpreter' />
8<link rel='contents' href='contents.html' title="Contents" />
9<link rel='last' href='about.html' title='About this document...' />
10<link rel='help' href='about.html' title='About this document...' />
11<link rel="next" href="lower-level-embedding.html" />
12<link rel="prev" href="embedding.html" />
13<link rel="parent" href="embedding.html" />
14<link rel="next" href="lower-level-embedding.html" />
15<meta name='aesop' content='information' />
16<title>5.1 Very High Level Embedding </title>
17</head>
18<body>
19<DIV CLASS="navigation">
20<div id='top-navigation-panel' xml:id='top-navigation-panel'>
21<table align="center" width="100%" cellpadding="0" cellspacing="2">
22<tr>
23<td class='online-navigation'><a rel="prev" title="5. Embedding Python in"
24 href="embedding.html"><img src='../icons/previous.png'
25 border='0' height='32' alt='Previous Page' width='32' /></A></td>
26<td class='online-navigation'><a rel="parent" title="5. Embedding Python in"
27 href="embedding.html"><img src='../icons/up.png'
28 border='0' height='32' alt='Up One Level' width='32' /></A></td>
29<td class='online-navigation'><a rel="next" title="5.2 Beyond Very High"
30 href="lower-level-embedding.html"><img src='../icons/next.png'
31 border='0' height='32' alt='Next Page' width='32' /></A></td>
32<td align="center" width="100%">Extending and Embedding the Python Interpreter</td>
33<td class='online-navigation'><a rel="contents" title="Table of Contents"
34 href="contents.html"><img src='../icons/contents.png'
35 border='0' height='32' alt='Contents' width='32' /></A></td>
36<td class='online-navigation'><img src='../icons/blank.png'
37 border='0' height='32' alt='' width='32' /></td>
38<td class='online-navigation'><img src='../icons/blank.png'
39 border='0' height='32' alt='' width='32' /></td>
40</tr></table>
41<div class='online-navigation'>
42<b class="navlabel">Previous:</b>
43<a class="sectref" rel="prev" href="embedding.html">5. Embedding Python in</A>
44<b class="navlabel">Up:</b>
45<a class="sectref" rel="parent" href="embedding.html">5. Embedding Python in</A>
46<b class="navlabel">Next:</b>
47<a class="sectref" rel="next" href="lower-level-embedding.html">5.2 Beyond Very High</A>
48</div>
49<hr /></div>
50</DIV>
51<!--End of Navigation Panel-->
52
53<H1><A NAME="SECTION007100000000000000000"></A><A NAME="high-level-embedding"></A>
54<BR>
555.1 Very High Level Embedding
56
57</H1>
58
59<P>
60The simplest form of embedding Python is the use of the very
61high level interface. This interface is intended to execute a
62Python script without needing to interact with the application
63directly. This can for example be used to perform some operation
64on a file.
65
66<P>
67<div class="verbatim"><pre>
68#include &lt;Python.h&gt;
69
70int
71main(int argc, char *argv[])
72{
73 Py_Initialize();
74 PyRun_SimpleString("from time import time,ctime\n"
75 "print 'Today is',ctime(time())\n");
76 Py_Finalize();
77 return 0;
78}
79</pre></div>
80
81<P>
82The above code first initializes the Python interpreter with
83<tt class="cfunction">Py_Initialize()</tt>, followed by the execution of a hard-coded
84Python script that print the date and time. Afterwards, the
85<tt class="cfunction">Py_Finalize()</tt> call shuts the interpreter down, followed by
86the end of the program. In a real program, you may want to get the
87Python script from another source, perhaps a text-editor routine, a
88file, or a database. Getting the Python code from a file can better
89be done by using the <tt class="cfunction">PyRun_SimpleFile()</tt> function, which
90saves you the trouble of allocating memory space and loading the file
91contents.
92
93<P>
94
95<DIV CLASS="navigation">
96<div class='online-navigation'>
97<p></p><hr />
98<table align="center" width="100%" cellpadding="0" cellspacing="2">
99<tr>
100<td class='online-navigation'><a rel="prev" title="5. Embedding Python in"
101 href="embedding.html"><img src='../icons/previous.png'
102 border='0' height='32' alt='Previous Page' width='32' /></A></td>
103<td class='online-navigation'><a rel="parent" title="5. Embedding Python in"
104 href="embedding.html"><img src='../icons/up.png'
105 border='0' height='32' alt='Up One Level' width='32' /></A></td>
106<td class='online-navigation'><a rel="next" title="5.2 Beyond Very High"
107 href="lower-level-embedding.html"><img src='../icons/next.png'
108 border='0' height='32' alt='Next Page' width='32' /></A></td>
109<td align="center" width="100%">Extending and Embedding the Python Interpreter</td>
110<td class='online-navigation'><a rel="contents" title="Table of Contents"
111 href="contents.html"><img src='../icons/contents.png'
112 border='0' height='32' alt='Contents' width='32' /></A></td>
113<td class='online-navigation'><img src='../icons/blank.png'
114 border='0' height='32' alt='' width='32' /></td>
115<td class='online-navigation'><img src='../icons/blank.png'
116 border='0' height='32' alt='' width='32' /></td>
117</tr></table>
118<div class='online-navigation'>
119<b class="navlabel">Previous:</b>
120<a class="sectref" rel="prev" href="embedding.html">5. Embedding Python in</A>
121<b class="navlabel">Up:</b>
122<a class="sectref" rel="parent" href="embedding.html">5. Embedding Python in</A>
123<b class="navlabel">Next:</b>
124<a class="sectref" rel="next" href="lower-level-embedding.html">5.2 Beyond Very High</A>
125</div>
126</div>
127<hr />
128<span class="release-info">Release 2.4.2, documentation updated on 28 September 2005.</span>
129</DIV>
130<!--End of Navigation Panel-->
131<ADDRESS>
132See <i><a href="about.html">About this document...</a></i> for information on suggesting changes.
133</ADDRESS>
134</BODY>
135</HTML>