| 1 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> |
| 2 | <html> |
| 3 | <head> |
| 4 | <link rel="STYLESHEET" href="ref.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="ref.html" title='Python Reference Manual' /> |
| 8 | <link rel='contents' href='contents.html' title="Contents" /> |
| 9 | <link rel='index' href='genindex.html' title='Index' /> |
| 10 | <link rel='last' href='about.html' title='About this document...' /> |
| 11 | <link rel='help' href='about.html' title='About this document...' /> |
| 12 | <link rel="prev" href="naming.html" /> |
| 13 | <link rel="parent" href="naming.html" /> |
| 14 | <link rel="next" href="exceptions.html" /> |
| 15 | <meta name='aesop' content='information' /> |
| 16 | <title>4.1.1 Interaction with dynamic features </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="4.1 Naming and binding" |
| 24 | href="naming.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="4.1 Naming and binding" |
| 27 | href="naming.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="4.2 Exceptions" |
| 30 | href="exceptions.html"><img src='../icons/next.png' |
| 31 | border='0' height='32' alt='Next Page' width='32' /></A></td> |
| 32 | <td align="center" width="100%">Python Reference Manual</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'><a rel="index" title="Index" |
| 39 | href="genindex.html"><img src='../icons/index.png' |
| 40 | border='0' height='32' alt='Index' width='32' /></A></td> |
| 41 | </tr></table> |
| 42 | <div class='online-navigation'> |
| 43 | <b class="navlabel">Previous:</b> |
| 44 | <a class="sectref" rel="prev" href="naming.html">4.1 Naming and binding</A> |
| 45 | <b class="navlabel">Up:</b> |
| 46 | <a class="sectref" rel="parent" href="naming.html">4.1 Naming and binding</A> |
| 47 | <b class="navlabel">Next:</b> |
| 48 | <a class="sectref" rel="next" href="exceptions.html">4.2 Exceptions</A> |
| 49 | </div> |
| 50 | <hr /></div> |
| 51 | </DIV> |
| 52 | <!--End of Navigation Panel--> |
| 53 | |
| 54 | <H2><A NAME="SECTION006110000000000000000"></A><A NAME="dynamic-features"></A> |
| 55 | <BR> |
| 56 | 4.1.1 Interaction with dynamic features |
| 57 | </H2> |
| 58 | |
| 59 | <P> |
| 60 | There are several cases where Python statements are illegal when |
| 61 | used in conjunction with nested scopes that contain free |
| 62 | variables. |
| 63 | |
| 64 | <P> |
| 65 | If a variable is referenced in an enclosing scope, it is illegal |
| 66 | to delete the name. An error will be reported at compile time. |
| 67 | |
| 68 | <P> |
| 69 | If the wild card form of import -- "<tt class="samp">import *</tt>" -- is used in a |
| 70 | function and the function contains or is a nested block with free |
| 71 | variables, the compiler will raise a SyntaxError. |
| 72 | |
| 73 | <P> |
| 74 | If <tt class="keyword">exec</tt> is used in a function and the function contains or |
| 75 | is a nested block with free variables, the compiler will raise a |
| 76 | <tt class="exception">SyntaxError</tt> unless the exec explicitly specifies the local |
| 77 | namespace for the <tt class="keyword">exec</tt>. (In other words, "<tt class="samp">exec obj</tt>"would be illegal, but "<tt class="samp">exec obj in ns</tt>" would be legal.) |
| 78 | |
| 79 | <P> |
| 80 | The <tt class="function">eval()</tt>, <tt class="function">execfile()</tt>, and <tt class="function">input()</tt> |
| 81 | functions and the <tt class="keyword">exec</tt> statement do not have access to the |
| 82 | full environment for resolving names. Names may be resolved in the |
| 83 | local and global namespaces of the caller. Free variables are not |
| 84 | resolved in the nearest enclosing namespace, but in the global |
| 85 | namespace.<A NAME="tex2html3" |
| 86 | HREF="#foot3527"><SUP>4.1</SUP></A>The <tt class="keyword">exec</tt> statement and the <tt class="function">eval()</tt> and |
| 87 | <tt class="function">execfile()</tt> functions have optional arguments to override |
| 88 | the global and local namespace. If only one namespace is specified, |
| 89 | it is used for both. |
| 90 | |
| 91 | <P> |
| 92 | <BR><HR><H4>Footnotes</H4> |
| 93 | <DL> |
| 94 | <DT><A NAME="foot3527">... |
| 95 | namespace.</A><A |
| 96 | href="dynamic-features.html#tex2html3"><SUP>4.1</SUP></A></DT> |
| 97 | <DD>This limitation occurs because the code that is |
| 98 | executed by these operations is not available at the time the |
| 99 | module is compiled. |
| 100 | |
| 101 | </DD> |
| 102 | </DL> |
| 103 | <DIV CLASS="navigation"> |
| 104 | <div class='online-navigation'> |
| 105 | <p></p><hr /> |
| 106 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> |
| 107 | <tr> |
| 108 | <td class='online-navigation'><a rel="prev" title="4.1 Naming and binding" |
| 109 | href="naming.html"><img src='../icons/previous.png' |
| 110 | border='0' height='32' alt='Previous Page' width='32' /></A></td> |
| 111 | <td class='online-navigation'><a rel="parent" title="4.1 Naming and binding" |
| 112 | href="naming.html"><img src='../icons/up.png' |
| 113 | border='0' height='32' alt='Up One Level' width='32' /></A></td> |
| 114 | <td class='online-navigation'><a rel="next" title="4.2 Exceptions" |
| 115 | href="exceptions.html"><img src='../icons/next.png' |
| 116 | border='0' height='32' alt='Next Page' width='32' /></A></td> |
| 117 | <td align="center" width="100%">Python Reference Manual</td> |
| 118 | <td class='online-navigation'><a rel="contents" title="Table of Contents" |
| 119 | href="contents.html"><img src='../icons/contents.png' |
| 120 | border='0' height='32' alt='Contents' width='32' /></A></td> |
| 121 | <td class='online-navigation'><img src='../icons/blank.png' |
| 122 | border='0' height='32' alt='' width='32' /></td> |
| 123 | <td class='online-navigation'><a rel="index" title="Index" |
| 124 | href="genindex.html"><img src='../icons/index.png' |
| 125 | border='0' height='32' alt='Index' width='32' /></A></td> |
| 126 | </tr></table> |
| 127 | <div class='online-navigation'> |
| 128 | <b class="navlabel">Previous:</b> |
| 129 | <a class="sectref" rel="prev" href="naming.html">4.1 Naming and binding</A> |
| 130 | <b class="navlabel">Up:</b> |
| 131 | <a class="sectref" rel="parent" href="naming.html">4.1 Naming and binding</A> |
| 132 | <b class="navlabel">Next:</b> |
| 133 | <a class="sectref" rel="next" href="exceptions.html">4.2 Exceptions</A> |
| 134 | </div> |
| 135 | </div> |
| 136 | <hr /> |
| 137 | <span class="release-info">Release 2.4.2, documentation updated on 28 September 2005.</span> |
| 138 | </DIV> |
| 139 | <!--End of Navigation Panel--> |
| 140 | <ADDRESS> |
| 141 | See <i><a href="about.html">About this document...</a></i> for information on suggesting changes. |
| 142 | </ADDRESS> |
| 143 | </BODY> |
| 144 | </HTML> |