| 1 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> |
| 2 | <html> |
| 3 | <head> |
| 4 | <link rel="STYLESHEET" href="lib.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="lib.html" title='Python Library Reference' /> |
| 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="warning-filter.html" /> |
| 13 | <link rel="parent" href="module-warnings.html" /> |
| 14 | <link rel="next" href="module-imp.html" /> |
| 15 | <meta name='aesop' content='information' /> |
| 16 | <title>3.20.3 Available Functions </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="3.20.2 The Warnings Filter" |
| 24 | href="warning-filter.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="3.20 warnings " |
| 27 | href="module-warnings.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="3.21 imp " |
| 30 | href="module-imp.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 Library Reference</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'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png' |
| 37 | border='0' height='32' alt='Module Index' width='32' /></a></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="warning-filter.html">3.20.2 The Warnings Filter</A> |
| 45 | <b class="navlabel">Up:</b> |
| 46 | <a class="sectref" rel="parent" href="module-warnings.html">3.20 warnings </A> |
| 47 | <b class="navlabel">Next:</b> |
| 48 | <a class="sectref" rel="next" href="module-imp.html">3.21 imp </A> |
| 49 | </div> |
| 50 | <hr /></div> |
| 51 | </DIV> |
| 52 | <!--End of Navigation Panel--> |
| 53 | |
| 54 | <H2><A NAME="SECTION0052030000000000000000"></A><A NAME="warning-functions"></A> |
| 55 | <BR> |
| 56 | 3.20.3 Available Functions |
| 57 | </H2> |
| 58 | |
| 59 | <P> |
| 60 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> |
| 61 | <td><nobr><b><tt id='l2h-689' xml:id='l2h-689' class="function">warn</tt></b>(</nobr></td> |
| 62 | <td><var>message</var><big>[</big><var>, category</var><big>[</big><var>, stacklevel</var><big>]</big><var></var><big>]</big><var></var>)</td></tr></table></dt> |
| 63 | <dd> |
| 64 | Issue a warning, or maybe ignore it or raise an exception. The |
| 65 | <var>category</var> argument, if given, must be a warning category class |
| 66 | (see above); it defaults to <tt class="exception">UserWarning</tt>. Alternatively |
| 67 | <var>message</var> can be a <tt class="exception">Warning</tt> instance, in which case |
| 68 | <var>category</var> will be ignored and <code>message.__class__</code> will be used. |
| 69 | In this case the message text will be <code>str(message)</code>. This function |
| 70 | raises an exception if the particular warning issued is changed |
| 71 | into an error by the warnings filter see above. The <var>stacklevel</var> |
| 72 | argument can be used by wrapper functions written in Python, like |
| 73 | this: |
| 74 | |
| 75 | <P> |
| 76 | <div class="verbatim"><pre> |
| 77 | def deprecation(message): |
| 78 | warnings.warn(message, DeprecationWarning, stacklevel=2) |
| 79 | </pre></div> |
| 80 | |
| 81 | <P> |
| 82 | This makes the warning refer to <tt class="function">deprecation()</tt>'s caller, |
| 83 | rather than to the source of <tt class="function">deprecation()</tt> itself (since |
| 84 | the latter would defeat the purpose of the warning message). |
| 85 | </dl> |
| 86 | |
| 87 | <P> |
| 88 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> |
| 89 | <td><nobr><b><tt id='l2h-690' xml:id='l2h-690' class="function">warn_explicit</tt></b>(</nobr></td> |
| 90 | <td><var>message, category, filename, |
| 91 | lineno</var><big>[</big><var>, module</var><big>[</big><var>, registry</var><big>]</big><var></var><big>]</big><var></var>)</td></tr></table></dt> |
| 92 | <dd> |
| 93 | This is a low-level interface to the functionality of |
| 94 | <tt class="function">warn()</tt>, passing in explicitly the message, category, |
| 95 | filename and line number, and optionally the module name and the |
| 96 | registry (which should be the <code>__warningregistry__</code> dictionary of |
| 97 | the module). The module name defaults to the filename with <code>.py</code> |
| 98 | stripped; if no registry is passed, the warning is never suppressed. |
| 99 | <var>message</var> must be a string and <var>category</var> a subclass of |
| 100 | <tt class="exception">Warning</tt> or <var>message</var> may be a <tt class="exception">Warning</tt> instance, |
| 101 | in which case <var>category</var> will be ignored. |
| 102 | </dl> |
| 103 | |
| 104 | <P> |
| 105 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> |
| 106 | <td><nobr><b><tt id='l2h-691' xml:id='l2h-691' class="function">showwarning</tt></b>(</nobr></td> |
| 107 | <td><var>message, category, filename, |
| 108 | lineno</var><big>[</big><var>, file</var><big>]</big><var></var>)</td></tr></table></dt> |
| 109 | <dd> |
| 110 | Write a warning to a file. The default implementation calls |
| 111 | <code>formatwarning(<var>message</var>, <var>category</var>, <var>filename</var>, |
| 112 | <var>lineno</var>)</code> and writes the resulting string to <var>file</var>, which |
| 113 | defaults to <code>sys.stderr</code>. You may replace this function with an |
| 114 | alternative implementation by assigning to |
| 115 | <code>warnings.showwarning</code>. |
| 116 | </dl> |
| 117 | |
| 118 | <P> |
| 119 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> |
| 120 | <td><nobr><b><tt id='l2h-692' xml:id='l2h-692' class="function">formatwarning</tt></b>(</nobr></td> |
| 121 | <td><var>message, category, filename, lineno</var>)</td></tr></table></dt> |
| 122 | <dd> |
| 123 | Format a warning the standard way. This returns a string which may |
| 124 | contain embedded newlines and ends in a newline. |
| 125 | </dl> |
| 126 | |
| 127 | <P> |
| 128 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> |
| 129 | <td><nobr><b><tt id='l2h-693' xml:id='l2h-693' class="function">filterwarnings</tt></b>(</nobr></td> |
| 130 | <td><var>action</var><big>[</big><var>, |
| 131 | message</var><big>[</big><var>, category</var><big>[</big><var>, |
| 132 | module</var><big>[</big><var>, lineno</var><big>[</big><var>, append</var><big>]</big><var></var><big>]</big><var></var><big>]</big><var></var><big>]</big><var></var><big>]</big><var></var>)</td></tr></table></dt> |
| 133 | <dd> |
| 134 | Insert an entry into the list of warnings filters. The entry is |
| 135 | inserted at the front by default; if <var>append</var> is true, it is |
| 136 | inserted at the end. |
| 137 | This checks the types of the arguments, compiles the message and |
| 138 | module regular expressions, and inserts them as a tuple in front |
| 139 | of the warnings filter. Entries inserted later override entries |
| 140 | inserted earlier, if both match a particular warning. Omitted |
| 141 | arguments default to a value that matches everything. |
| 142 | </dl> |
| 143 | |
| 144 | <P> |
| 145 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> |
| 146 | <td><nobr><b><tt id='l2h-694' xml:id='l2h-694' class="function">resetwarnings</tt></b>(</nobr></td> |
| 147 | <td><var></var>)</td></tr></table></dt> |
| 148 | <dd> |
| 149 | Reset the warnings filter. This discards the effect of all previous |
| 150 | calls to <tt class="function">filterwarnings()</tt>, including that of the |
| 151 | <b class="programopt">-W</b> command line options. |
| 152 | </dl> |
| 153 | |
| 154 | <DIV CLASS="navigation"> |
| 155 | <div class='online-navigation'> |
| 156 | <p></p><hr /> |
| 157 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> |
| 158 | <tr> |
| 159 | <td class='online-navigation'><a rel="prev" title="3.20.2 The Warnings Filter" |
| 160 | href="warning-filter.html"><img src='../icons/previous.png' |
| 161 | border='0' height='32' alt='Previous Page' width='32' /></A></td> |
| 162 | <td class='online-navigation'><a rel="parent" title="3.20 warnings " |
| 163 | href="module-warnings.html"><img src='../icons/up.png' |
| 164 | border='0' height='32' alt='Up One Level' width='32' /></A></td> |
| 165 | <td class='online-navigation'><a rel="next" title="3.21 imp " |
| 166 | href="module-imp.html"><img src='../icons/next.png' |
| 167 | border='0' height='32' alt='Next Page' width='32' /></A></td> |
| 168 | <td align="center" width="100%">Python Library Reference</td> |
| 169 | <td class='online-navigation'><a rel="contents" title="Table of Contents" |
| 170 | href="contents.html"><img src='../icons/contents.png' |
| 171 | border='0' height='32' alt='Contents' width='32' /></A></td> |
| 172 | <td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png' |
| 173 | border='0' height='32' alt='Module Index' width='32' /></a></td> |
| 174 | <td class='online-navigation'><a rel="index" title="Index" |
| 175 | href="genindex.html"><img src='../icons/index.png' |
| 176 | border='0' height='32' alt='Index' width='32' /></A></td> |
| 177 | </tr></table> |
| 178 | <div class='online-navigation'> |
| 179 | <b class="navlabel">Previous:</b> |
| 180 | <a class="sectref" rel="prev" href="warning-filter.html">3.20.2 The Warnings Filter</A> |
| 181 | <b class="navlabel">Up:</b> |
| 182 | <a class="sectref" rel="parent" href="module-warnings.html">3.20 warnings </A> |
| 183 | <b class="navlabel">Next:</b> |
| 184 | <a class="sectref" rel="next" href="module-imp.html">3.21 imp </A> |
| 185 | </div> |
| 186 | </div> |
| 187 | <hr /> |
| 188 | <span class="release-info">Release 2.4.2, documentation updated on 28 September 2005.</span> |
| 189 | </DIV> |
| 190 | <!--End of Navigation Panel--> |
| 191 | <ADDRESS> |
| 192 | See <i><a href="about.html">About this document...</a></i> for information on suggesting changes. |
| 193 | </ADDRESS> |
| 194 | </BODY> |
| 195 | </HTML> |