Sophie

Sophie

distrib > Mageia > 6 > armv5tl > by-pkgid > a600cd26dfe6bfd8c11f12bce5cb0eee > files > 611

python3-docs-3.5.3-1.1.mga6.noarch.rpm

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>Python on Windows FAQ &mdash; Python 3.5.3 documentation</title>
    
    <link rel="stylesheet" href="../_static/pydoctheme.css" type="text/css" />
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
    
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../',
        VERSION:     '3.5.3',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="../_static/jquery.js"></script>
    <script type="text/javascript" src="../_static/underscore.js"></script>
    <script type="text/javascript" src="../_static/doctools.js"></script>
    <script type="text/javascript" src="../_static/sidebar.js"></script>
    <link rel="search" type="application/opensearchdescription+xml"
          title="Search within Python 3.5.3 documentation"
          href="../_static/opensearch.xml"/>
    <link rel="author" title="About these documents" href="../about.html" />
    <link rel="copyright" title="Copyright" href="../copyright.html" />
    <link rel="top" title="Python 3.5.3 documentation" href="../contents.html" />
    <link rel="up" title="Python Frequently Asked Questions" href="index.html" />
    <link rel="next" title="Graphic User Interface FAQ" href="gui.html" />
    <link rel="prev" title="Extending/Embedding FAQ" href="extending.html" />
    <link rel="shortcut icon" type="image/png" href="../_static/py.png" />
    
    <script type="text/javascript" src="../_static/copybutton.js"></script>
    <script type="text/javascript" src="../_static/version_switch.js"></script>
    
    
 

  </head>
  <body role="document">  
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="gui.html" title="Graphic User Interface FAQ"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="extending.html" title="Extending/Embedding FAQ"
             accesskey="P">previous</a> |</li>
        <li><img src="../_static/py.png" alt=""
                 style="vertical-align: middle; margin-top: -1px"/></li>
        <li><a href="https://www.python.org/">Python</a> &raquo;</li>
        <li>
          <span class="version_switcher_placeholder">3.5.3</span>
          <a href="../index.html">Documentation </a> &raquo;
        </li>

          <li class="nav-item nav-item-1"><a href="index.html" accesskey="U">Python Frequently Asked Questions</a> &raquo;</li>
    <li class="right">
        

    <div class="inline-search" style="display: none" role="search">
        <form class="inline-search" action="../search.html" method="get">
          <input placeholder="Quick search" type="text" name="q" />
          <input type="submit" value="Go" />
          <input type="hidden" name="check_keywords" value="yes" />
          <input type="hidden" name="area" value="default" />
        </form>
    </div>
    <script type="text/javascript">$('.inline-search').show(0);</script>
         |
    </li>

      </ul>
    </div>    

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body" role="main">
            
  <div class="section" id="python-on-windows-faq">
<span id="windows-faq"></span><h1><a class="toc-backref" href="#id1">Python on Windows FAQ</a><a class="headerlink" href="#python-on-windows-faq" title="Permalink to this headline">¶</a></h1>
<div class="contents topic" id="contents">
<p class="topic-title first">Contents</p>
<ul class="simple">
<li><a class="reference internal" href="#python-on-windows-faq" id="id1">Python on Windows FAQ</a><ul>
<li><a class="reference internal" href="#how-do-i-run-a-python-program-under-windows" id="id2">How do I run a Python program under Windows?</a></li>
<li><a class="reference internal" href="#how-do-i-make-python-scripts-executable" id="id3">How do I make Python scripts executable?</a></li>
<li><a class="reference internal" href="#why-does-python-sometimes-take-so-long-to-start" id="id4">Why does Python sometimes take so long to start?</a></li>
<li><a class="reference internal" href="#how-do-i-make-an-executable-from-a-python-script" id="id5">How do I make an executable from a Python script?</a></li>
<li><a class="reference internal" href="#is-a-pyd-file-the-same-as-a-dll" id="id6">Is a <code class="docutils literal"><span class="pre">*.pyd</span></code> file the same as a DLL?</a></li>
<li><a class="reference internal" href="#how-can-i-embed-python-into-a-windows-application" id="id7">How can I embed Python into a Windows application?</a></li>
<li><a class="reference internal" href="#how-do-i-keep-editors-from-inserting-tabs-into-my-python-source" id="id8">How do I keep editors from inserting tabs into my Python source?</a></li>
<li><a class="reference internal" href="#how-do-i-check-for-a-keypress-without-blocking" id="id9">How do I check for a keypress without blocking?</a></li>
<li><a class="reference internal" href="#how-do-i-emulate-os-kill-in-windows" id="id10">How do I emulate os.kill() in Windows?</a></li>
<li><a class="reference internal" href="#how-do-i-extract-the-downloaded-documentation-on-windows" id="id11">How do I extract the downloaded documentation on Windows?</a></li>
</ul>
</li>
</ul>
</div>
<div class="section" id="how-do-i-run-a-python-program-under-windows">
<h2><a class="toc-backref" href="#id2">How do I run a Python program under Windows?</a><a class="headerlink" href="#how-do-i-run-a-python-program-under-windows" title="Permalink to this headline">¶</a></h2>
<p>This is not necessarily a straightforward question. If you are already familiar
with running programs from the Windows command line then everything will seem
obvious; otherwise, you might need a little more guidance.</p>
<div class="sidebar">
<p class="first sidebar-title"><a class="reference external" href="http://showmedo.com/videotutorials/series?name=pythonOzsvaldPyNewbieSeries"><img alt="Python Development on XP" src="../_images/python-video-icon.png" /></a></p>
<p class="sidebar-subtitle"><a class="reference external" href="http://showmedo.com/videotutorials/series?name=pythonOzsvaldPyNewbieSeries">Python Development on XP</a></p>
<p class="last">This series of screencasts aims to get you up and running with Python on
Windows XP.  The knowledge is distilled into 1.5 hours and will get you up
and running with the right Python distribution, coding in your choice of IDE,
and debugging and writing solid code with unit-tests.</p>
</div>
<p>Unless you use some sort of integrated development environment, you will end up
<em>typing</em> Windows commands into what is variously referred to as a &#8220;DOS window&#8221;
or &#8220;Command prompt window&#8221;.  Usually you can create such a window from your
Start menu; under Windows 7 the menu selection is <span class="menuselection">Start ‣
Programs ‣ Accessories ‣ Command Prompt</span>.  You should be able to recognize
when you have started such a window because you will see a Windows &#8220;command
prompt&#8221;, which usually looks like this:</p>
<div class="highlight-python3"><div class="highlight"><pre><span></span><span class="n">C</span><span class="p">:</span>\<span class="o">&gt;</span>
</pre></div>
</div>
<p>The letter may be different, and there might be other things after it, so you
might just as easily see something like:</p>
<div class="highlight-python3"><div class="highlight"><pre><span></span><span class="n">D</span><span class="p">:</span>\<span class="n">YourName</span>\<span class="n">Projects</span>\<span class="n">Python</span><span class="o">&gt;</span>
</pre></div>
</div>
<p>depending on how your computer has been set up and what else you have recently
done with it.  Once you have started such a window, you are well on the way to
running Python programs.</p>
<p>You need to realize that your Python scripts have to be processed by another
program called the Python <em>interpreter</em>.  The interpreter reads your script,
compiles it into bytecodes, and then executes the bytecodes to run your
program. So, how do you arrange for the interpreter to handle your Python?</p>
<p>First, you need to make sure that your command window recognises the word
&#8220;python&#8221; as an instruction to start the interpreter.  If you have opened a
command window, you should try entering the command <code class="docutils literal"><span class="pre">python</span></code> and hitting
return.:</p>
<div class="highlight-python3"><div class="highlight"><pre><span></span><span class="n">C</span><span class="p">:</span>\<span class="n">Users</span>\<span class="n">YourName</span><span class="o">&gt;</span> <span class="n">python</span>
</pre></div>
</div>
<p>You should then see something like:</p>
<div class="highlight-python3"><div class="highlight"><pre><span></span><span class="n">Python</span> <span class="mf">3.3</span><span class="o">.</span><span class="mi">0</span> <span class="p">(</span><span class="n">v3</span><span class="o">.</span><span class="mf">3.0</span><span class="p">:</span><span class="n">bd8afb90ebf2</span><span class="p">,</span> <span class="n">Sep</span> <span class="mi">29</span> <span class="mi">2012</span><span class="p">,</span> <span class="mi">10</span><span class="p">:</span><span class="mi">55</span><span class="p">:</span><span class="mi">48</span><span class="p">)</span> <span class="p">[</span><span class="n">MSC</span> <span class="n">v</span><span class="o">.</span><span class="mi">1600</span> <span class="mi">32</span> <span class="n">bit</span> <span class="p">(</span><span class="n">Intel</span><span class="p">)]</span> <span class="n">on</span> <span class="n">win32</span>
<span class="n">Type</span> <span class="s2">&quot;help&quot;</span><span class="p">,</span> <span class="s2">&quot;copyright&quot;</span><span class="p">,</span> <span class="s2">&quot;credits&quot;</span> <span class="ow">or</span> <span class="s2">&quot;license&quot;</span> <span class="k">for</span> <span class="n">more</span> <span class="n">information</span><span class="o">.</span>
<span class="o">&gt;&gt;&gt;</span>
</pre></div>
</div>
<p>You have started the interpreter in &#8220;interactive mode&#8221;. That means you can enter
Python statements or expressions interactively and have them executed or
evaluated while you wait.  This is one of Python&#8217;s strongest features.  Check it
by entering a few expressions of your choice and seeing the results:</p>
<div class="highlight-python3"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Hello&quot;</span><span class="p">)</span>
<span class="go">Hello</span>
<span class="gp">&gt;&gt;&gt; </span><span class="s2">&quot;Hello&quot;</span> <span class="o">*</span> <span class="mi">3</span>
<span class="go">&#39;HelloHelloHello&#39;</span>
</pre></div>
</div>
<p>Many people use the interactive mode as a convenient yet highly programmable
calculator.  When you want to end your interactive Python session, hold the <code class="kbd docutils literal"><span class="pre">Ctrl</span></code>
key down while you enter a <code class="kbd docutils literal"><span class="pre">Z</span></code>, then hit the &#8220;<code class="kbd docutils literal"><span class="pre">Enter</span></code>&#8221; key to get back to your
Windows command prompt.</p>
<p>You may also find that you have a Start-menu entry such as <span class="menuselection">Start
‣ Programs ‣ Python 3.3 ‣ Python (command line)</span> that results in you
seeing the <code class="docutils literal"><span class="pre">&gt;&gt;&gt;</span></code> prompt in a new window.  If so, the window will disappear
after you enter the <code class="kbd docutils literal"><span class="pre">Ctrl-Z</span></code> character; Windows is running a single &#8220;python&#8221;
command in the window, and closes it when you terminate the interpreter.</p>
<p>If the <code class="docutils literal"><span class="pre">python</span></code> command, instead of displaying the interpreter prompt <code class="docutils literal"><span class="pre">&gt;&gt;&gt;</span></code>,
gives you a message like:</p>
<div class="highlight-python3"><div class="highlight"><pre><span></span><span class="s1">&#39;python&#39;</span> <span class="ow">is</span> <span class="ow">not</span> <span class="n">recognized</span> <span class="k">as</span> <span class="n">an</span> <span class="n">internal</span> <span class="ow">or</span> <span class="n">external</span> <span class="n">command</span><span class="p">,</span> <span class="n">operable</span> <span class="n">program</span> <span class="ow">or</span> <span class="n">batch</span> <span class="n">file</span><span class="o">.</span>
</pre></div>
</div>
<div class="sidebar">
<p class="first sidebar-title"><a class="reference external" href="http://showmedo.com/videotutorials/video?name=960000&amp;fromSeriesID=96"><img alt="Adding Python to DOS Path" src="../_images/python-video-icon.png" /></a></p>
<p class="sidebar-subtitle"><a class="reference external" href="http://showmedo.com/videotutorials/video?name=960000&amp;fromSeriesID=96">Adding Python to DOS Path</a></p>
<p class="last">Python is not added to the DOS path by default.  This screencast will walk
you through the steps to add the correct entry to the <cite>System Path</cite>, allowing
Python to be executed from the command-line by all users.</p>
</div>
<p>or:</p>
<div class="highlight-python3"><div class="highlight"><pre><span></span><span class="n">Bad</span> <span class="n">command</span> <span class="ow">or</span> <span class="n">filename</span>
</pre></div>
</div>
<p>then you need to make sure that your computer knows where to find the Python
interpreter.  To do this you will have to modify a setting called PATH, which is
a list of directories where Windows will look for programs.</p>
<p>You should arrange for Python&#8217;s installation directory to be added to the PATH
of every command window as it starts.  If you installed Python fairly recently
then the command</p>
<div class="highlight-python3"><div class="highlight"><pre><span></span><span class="nb">dir</span> <span class="n">C</span><span class="p">:</span>\<span class="n">py</span><span class="o">*</span>
</pre></div>
</div>
<p>will probably tell you where it is installed; the usual location is something
like <code class="docutils literal"><span class="pre">C:\Python33</span></code>.  Otherwise you will be reduced to a search of your whole
disk ... use <span class="menuselection">Tools ‣ Find</span> or hit the <span class="guilabel">Search</span>
button and look for &#8220;python.exe&#8221;.  Supposing you discover that Python is
installed in the <code class="docutils literal"><span class="pre">C:\Python33</span></code> directory (the default at the time of writing),
you should make sure that entering the command</p>
<div class="highlight-python3"><div class="highlight"><pre><span></span><span class="n">c</span><span class="p">:</span>\<span class="n">Python33</span>\<span class="n">python</span>
</pre></div>
</div>
<p>starts up the interpreter as above (and don&#8217;t forget you&#8217;ll need a &#8220;<code class="kbd docutils literal"><span class="pre">Ctrl-Z</span></code>&#8221; and
an &#8220;<code class="kbd docutils literal"><span class="pre">Enter</span></code>&#8221; to get out of it). Once you have verified the directory, you can
add it to the system path to make it easier to start Python by just running
the <code class="docutils literal"><span class="pre">python</span></code> command. This is currently an option in the installer as of
CPython 3.3.</p>
<p>More information about environment variables can be found on the
<a class="reference internal" href="../using/windows.html#setting-envvars"><span>Using Python on Windows</span></a> page.</p>
</div>
<div class="section" id="how-do-i-make-python-scripts-executable">
<h2><a class="toc-backref" href="#id3">How do I make Python scripts executable?</a><a class="headerlink" href="#how-do-i-make-python-scripts-executable" title="Permalink to this headline">¶</a></h2>
<p>On Windows, the standard Python installer already associates the .py
extension with a file type (Python.File) and gives that file type an open
command that runs the interpreter (<code class="docutils literal"><span class="pre">D:\Program</span> <span class="pre">Files\Python\python.exe</span> <span class="pre">&quot;%1&quot;</span>
<span class="pre">%*</span></code>).  This is enough to make scripts executable from the command prompt as
&#8216;foo.py&#8217;.  If you&#8217;d rather be able to execute the script by simple typing &#8216;foo&#8217;
with no extension you need to add .py to the PATHEXT environment variable.</p>
</div>
<div class="section" id="why-does-python-sometimes-take-so-long-to-start">
<h2><a class="toc-backref" href="#id4">Why does Python sometimes take so long to start?</a><a class="headerlink" href="#why-does-python-sometimes-take-so-long-to-start" title="Permalink to this headline">¶</a></h2>
<p>Usually Python starts very quickly on Windows, but occasionally there are bug
reports that Python suddenly begins to take a long time to start up.  This is
made even more puzzling because Python will work fine on other Windows systems
which appear to be configured identically.</p>
<p>The problem may be caused by a misconfiguration of virus checking software on
the problem machine.  Some virus scanners have been known to introduce startup
overhead of two orders of magnitude when the scanner is configured to monitor
all reads from the filesystem.  Try checking the configuration of virus scanning
software on your systems to ensure that they are indeed configured identically.
McAfee, when configured to scan all file system read activity, is a particular
offender.</p>
</div>
<div class="section" id="how-do-i-make-an-executable-from-a-python-script">
<h2><a class="toc-backref" href="#id5">How do I make an executable from a Python script?</a><a class="headerlink" href="#how-do-i-make-an-executable-from-a-python-script" title="Permalink to this headline">¶</a></h2>
<p>See <a class="reference external" href="http://cx-freeze.sourceforge.net/">http://cx-freeze.sourceforge.net/</a> for a distutils extension that allows you
to create console and GUI executables from Python code.
<a class="reference external" href="http://www.py2exe.org/">py2exe</a>, the most popular extension for building
Python 2.x-based executables, does not yet support Python 3 but a version that
does is in development.</p>
</div>
<div class="section" id="is-a-pyd-file-the-same-as-a-dll">
<h2><a class="toc-backref" href="#id6">Is a <code class="docutils literal"><span class="pre">*.pyd</span></code> file the same as a DLL?</a><a class="headerlink" href="#is-a-pyd-file-the-same-as-a-dll" title="Permalink to this headline">¶</a></h2>
<p>Yes, .pyd files are dll&#8217;s, but there are a few differences.  If you have a DLL
named <code class="docutils literal"><span class="pre">foo.pyd</span></code>, then it must have a function <code class="docutils literal"><span class="pre">PyInit_foo()</span></code>.  You can then
write Python &#8220;import foo&#8221;, and Python will search for foo.pyd (as well as
foo.py, foo.pyc) and if it finds it, will attempt to call <code class="docutils literal"><span class="pre">PyInit_foo()</span></code> to
initialize it.  You do not link your .exe with foo.lib, as that would cause
Windows to require the DLL to be present.</p>
<p>Note that the search path for foo.pyd is PYTHONPATH, not the same as the path
that Windows uses to search for foo.dll.  Also, foo.pyd need not be present to
run your program, whereas if you linked your program with a dll, the dll is
required.  Of course, foo.pyd is required if you want to say <code class="docutils literal"><span class="pre">import</span> <span class="pre">foo</span></code>.  In
a DLL, linkage is declared in the source code with <code class="docutils literal"><span class="pre">__declspec(dllexport)</span></code>.
In a .pyd, linkage is defined in a list of available functions.</p>
</div>
<div class="section" id="how-can-i-embed-python-into-a-windows-application">
<h2><a class="toc-backref" href="#id7">How can I embed Python into a Windows application?</a><a class="headerlink" href="#how-can-i-embed-python-into-a-windows-application" title="Permalink to this headline">¶</a></h2>
<p>Embedding the Python interpreter in a Windows app can be summarized as follows:</p>
<ol class="arabic">
<li><p class="first">Do _not_ build Python into your .exe file directly.  On Windows, Python must
be a DLL to handle importing modules that are themselves DLL&#8217;s.  (This is the
first key undocumented fact.)  Instead, link to <code class="file docutils literal"><span class="pre">python</span><em><span class="pre">NN</span></em><span class="pre">.dll</span></code>; it is
typically installed in <code class="docutils literal"><span class="pre">C:\Windows\System</span></code>.  <em>NN</em> is the Python version, a
number such as &#8220;33&#8221; for Python 3.3.</p>
<p>You can link to Python in two different ways.  Load-time linking means
linking against <code class="file docutils literal"><span class="pre">python</span><em><span class="pre">NN</span></em><span class="pre">.lib</span></code>, while run-time linking means linking
against <code class="file docutils literal"><span class="pre">python</span><em><span class="pre">NN</span></em><span class="pre">.dll</span></code>.  (General note: <code class="file docutils literal"><span class="pre">python</span><em><span class="pre">NN</span></em><span class="pre">.lib</span></code> is the
so-called &#8220;import lib&#8221; corresponding to <code class="file docutils literal"><span class="pre">python</span><em><span class="pre">NN</span></em><span class="pre">.dll</span></code>.  It merely
defines symbols for the linker.)</p>
<p>Run-time linking greatly simplifies link options; everything happens at run
time.  Your code must load <code class="file docutils literal"><span class="pre">python</span><em><span class="pre">NN</span></em><span class="pre">.dll</span></code> using the Windows
<code class="docutils literal"><span class="pre">LoadLibraryEx()</span></code> routine.  The code must also use access routines and data
in <code class="file docutils literal"><span class="pre">python</span><em><span class="pre">NN</span></em><span class="pre">.dll</span></code> (that is, Python&#8217;s C API&#8217;s) using pointers obtained
by the Windows <code class="docutils literal"><span class="pre">GetProcAddress()</span></code> routine.  Macros can make using these
pointers transparent to any C code that calls routines in Python&#8217;s C API.</p>
<p>Borland note: convert <code class="file docutils literal"><span class="pre">python</span><em><span class="pre">NN</span></em><span class="pre">.lib</span></code> to OMF format using Coff2Omf.exe
first.</p>
</li>
<li><p class="first">If you use SWIG, it is easy to create a Python &#8220;extension module&#8221; that will
make the app&#8217;s data and methods available to Python.  SWIG will handle just
about all the grungy details for you.  The result is C code that you link
<em>into</em> your .exe file (!)  You do _not_ have to create a DLL file, and this
also simplifies linking.</p>
</li>
<li><p class="first">SWIG will create an init function (a C function) whose name depends on the
name of the extension module.  For example, if the name of the module is leo,
the init function will be called initleo().  If you use SWIG shadow classes,
as you should, the init function will be called initleoc().  This initializes
a mostly hidden helper class used by the shadow class.</p>
<p>The reason you can link the C code in step 2 into your .exe file is that
calling the initialization function is equivalent to importing the module
into Python! (This is the second key undocumented fact.)</p>
</li>
<li><p class="first">In short, you can use the following code to initialize the Python interpreter
with your extension module.</p>
<div class="highlight-c"><div class="highlight"><pre><span></span><span class="cp">#include</span> <span class="cpf">&quot;python.h&quot;</span><span class="cp"></span>
<span class="p">...</span>
<span class="n">Py_Initialize</span><span class="p">();</span>  <span class="c1">// Initialize Python.</span>
<span class="n">initmyAppc</span><span class="p">();</span>  <span class="c1">// Initialize (import) the helper class.</span>
<span class="n">PyRun_SimpleString</span><span class="p">(</span><span class="s">&quot;import myApp&quot;</span><span class="p">);</span>  <span class="c1">// Import the shadow class.</span>
</pre></div>
</div>
</li>
<li><p class="first">There are two problems with Python&#8217;s C API which will become apparent if you
use a compiler other than MSVC, the compiler used to build pythonNN.dll.</p>
<p>Problem 1: The so-called &#8220;Very High Level&#8221; functions that take FILE *
arguments will not work in a multi-compiler environment because each
compiler&#8217;s notion of a struct FILE will be different.  From an implementation
standpoint these are very _low_ level functions.</p>
<p>Problem 2: SWIG generates the following code when generating wrappers to void
functions:</p>
<div class="highlight-c"><div class="highlight"><pre><span></span><span class="n">Py_INCREF</span><span class="p">(</span><span class="n">Py_None</span><span class="p">);</span>
<span class="n">_resultobj</span> <span class="o">=</span> <span class="n">Py_None</span><span class="p">;</span>
<span class="k">return</span> <span class="n">_resultobj</span><span class="p">;</span>
</pre></div>
</div>
<p>Alas, Py_None is a macro that expands to a reference to a complex data
structure called _Py_NoneStruct inside pythonNN.dll.  Again, this code will
fail in a mult-compiler environment.  Replace such code by:</p>
<div class="highlight-c"><div class="highlight"><pre><span></span><span class="k">return</span> <span class="nf">Py_BuildValue</span><span class="p">(</span><span class="s">&quot;&quot;</span><span class="p">);</span>
</pre></div>
</div>
<p>It may be possible to use SWIG&#8217;s <code class="docutils literal"><span class="pre">%typemap</span></code> command to make the change
automatically, though I have not been able to get this to work (I&#8217;m a
complete SWIG newbie).</p>
</li>
<li><p class="first">Using a Python shell script to put up a Python interpreter window from inside
your Windows app is not a good idea; the resulting window will be independent
of your app&#8217;s windowing system.  Rather, you (or the wxPythonWindow class)
should create a &#8220;native&#8221; interpreter window.  It is easy to connect that
window to the Python interpreter.  You can redirect Python&#8217;s i/o to _any_
object that supports read and write, so all you need is a Python object
(defined in your extension module) that contains read() and write() methods.</p>
</li>
</ol>
</div>
<div class="section" id="how-do-i-keep-editors-from-inserting-tabs-into-my-python-source">
<h2><a class="toc-backref" href="#id8">How do I keep editors from inserting tabs into my Python source?</a><a class="headerlink" href="#how-do-i-keep-editors-from-inserting-tabs-into-my-python-source" title="Permalink to this headline">¶</a></h2>
<p>The FAQ does not recommend using tabs, and the Python style guide, <span class="target" id="index-0"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0008"><strong>PEP 8</strong></a>,
recommends 4 spaces for distributed Python code; this is also the Emacs
python-mode default.</p>
<p>Under any editor, mixing tabs and spaces is a bad idea.  MSVC is no different in
this respect, and is easily configured to use spaces: Take <span class="menuselection">Tools
‣ Options ‣ Tabs</span>, and for file type &#8220;Default&#8221; set &#8220;Tab size&#8221; and &#8220;Indent
size&#8221; to 4, and select the &#8220;Insert spaces&#8221; radio button.</p>
<p>If you suspect mixed tabs and spaces are causing problems in leading whitespace,
run Python with the <code class="xref std std-option docutils literal"><span class="pre">-t</span></code> switch or run <code class="docutils literal"><span class="pre">Tools/Scripts/tabnanny.py</span></code> to
check a directory tree in batch mode.</p>
</div>
<div class="section" id="how-do-i-check-for-a-keypress-without-blocking">
<h2><a class="toc-backref" href="#id9">How do I check for a keypress without blocking?</a><a class="headerlink" href="#how-do-i-check-for-a-keypress-without-blocking" title="Permalink to this headline">¶</a></h2>
<p>Use the msvcrt module.  This is a standard Windows-specific extension module.
It defines a function <code class="docutils literal"><span class="pre">kbhit()</span></code> which checks whether a keyboard hit is
present, and <code class="docutils literal"><span class="pre">getch()</span></code> which gets one character without echoing it.</p>
</div>
<div class="section" id="how-do-i-emulate-os-kill-in-windows">
<h2><a class="toc-backref" href="#id10">How do I emulate os.kill() in Windows?</a><a class="headerlink" href="#how-do-i-emulate-os-kill-in-windows" title="Permalink to this headline">¶</a></h2>
<p>Prior to Python 2.7 and 3.2, to terminate a process, you can use <a class="reference internal" href="../library/ctypes.html#module-ctypes" title="ctypes: A foreign function library for Python."><code class="xref py py-mod docutils literal"><span class="pre">ctypes</span></code></a>:</p>
<div class="highlight-python3"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">ctypes</span>

<span class="k">def</span> <span class="nf">kill</span><span class="p">(</span><span class="n">pid</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;kill function for Win32&quot;&quot;&quot;</span>
    <span class="n">kernel32</span> <span class="o">=</span> <span class="n">ctypes</span><span class="o">.</span><span class="n">windll</span><span class="o">.</span><span class="n">kernel32</span>
    <span class="n">handle</span> <span class="o">=</span> <span class="n">kernel32</span><span class="o">.</span><span class="n">OpenProcess</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="n">pid</span><span class="p">)</span>
    <span class="k">return</span> <span class="p">(</span><span class="mi">0</span> <span class="o">!=</span> <span class="n">kernel32</span><span class="o">.</span><span class="n">TerminateProcess</span><span class="p">(</span><span class="n">handle</span><span class="p">,</span> <span class="mi">0</span><span class="p">))</span>
</pre></div>
</div>
<p>In 2.7 and 3.2, <a class="reference internal" href="../library/os.html#os.kill" title="os.kill"><code class="xref py py-func docutils literal"><span class="pre">os.kill()</span></code></a> is implemented similar to the above function,
with the additional feature of being able to send <code class="kbd docutils literal"><span class="pre">Ctrl+C</span></code> and <code class="kbd docutils literal"><span class="pre">Ctrl+Break</span></code>
to console subprocesses which are designed to handle those signals. See
<a class="reference internal" href="../library/os.html#os.kill" title="os.kill"><code class="xref py py-func docutils literal"><span class="pre">os.kill()</span></code></a> for further details.</p>
</div>
<div class="section" id="how-do-i-extract-the-downloaded-documentation-on-windows">
<h2><a class="toc-backref" href="#id11">How do I extract the downloaded documentation on Windows?</a><a class="headerlink" href="#how-do-i-extract-the-downloaded-documentation-on-windows" title="Permalink to this headline">¶</a></h2>
<p>Sometimes, when you download the documentation package to a Windows machine
using a web browser, the file extension of the saved file ends up being .EXE.
This is a mistake; the extension should be .TGZ.</p>
<p>Simply rename the downloaded file to have the .TGZ extension, and WinZip will be
able to handle it.  (If your copy of WinZip doesn&#8217;t, get a newer one from
<a class="reference external" href="https://www.winzip.com">https://www.winzip.com</a>.)</p>
</div>
</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
  <h3><a href="../contents.html">Table Of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">Python on Windows FAQ</a><ul>
<li><a class="reference internal" href="#how-do-i-run-a-python-program-under-windows">How do I run a Python program under Windows?</a></li>
<li><a class="reference internal" href="#how-do-i-make-python-scripts-executable">How do I make Python scripts executable?</a></li>
<li><a class="reference internal" href="#why-does-python-sometimes-take-so-long-to-start">Why does Python sometimes take so long to start?</a></li>
<li><a class="reference internal" href="#how-do-i-make-an-executable-from-a-python-script">How do I make an executable from a Python script?</a></li>
<li><a class="reference internal" href="#is-a-pyd-file-the-same-as-a-dll">Is a <code class="docutils literal"><span class="pre">*.pyd</span></code> file the same as a DLL?</a></li>
<li><a class="reference internal" href="#how-can-i-embed-python-into-a-windows-application">How can I embed Python into a Windows application?</a></li>
<li><a class="reference internal" href="#how-do-i-keep-editors-from-inserting-tabs-into-my-python-source">How do I keep editors from inserting tabs into my Python source?</a></li>
<li><a class="reference internal" href="#how-do-i-check-for-a-keypress-without-blocking">How do I check for a keypress without blocking?</a></li>
<li><a class="reference internal" href="#how-do-i-emulate-os-kill-in-windows">How do I emulate os.kill() in Windows?</a></li>
<li><a class="reference internal" href="#how-do-i-extract-the-downloaded-documentation-on-windows">How do I extract the downloaded documentation on Windows?</a></li>
</ul>
</li>
</ul>

  <h4>Previous topic</h4>
  <p class="topless"><a href="extending.html"
                        title="previous chapter">Extending/Embedding FAQ</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="gui.html"
                        title="next chapter">Graphic User Interface FAQ</a></p>
  <div role="note" aria-label="source link">
    <h3>This Page</h3>
    <ul class="this-page-menu">
      <li><a href="../bugs.html">Report a Bug</a></li>
      <li><a href="../_sources/faq/windows.txt"
            rel="nofollow">Show Source</a></li>
    </ul>
  </div>
        </div>
      </div>
      <div class="clearer"></div>
    </div>  
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="gui.html" title="Graphic User Interface FAQ"
             >next</a> |</li>
        <li class="right" >
          <a href="extending.html" title="Extending/Embedding FAQ"
             >previous</a> |</li>
        <li><img src="../_static/py.png" alt=""
                 style="vertical-align: middle; margin-top: -1px"/></li>
        <li><a href="https://www.python.org/">Python</a> &raquo;</li>
        <li>
          <span class="version_switcher_placeholder">3.5.3</span>
          <a href="../index.html">Documentation </a> &raquo;
        </li>

          <li class="nav-item nav-item-1"><a href="index.html" >Python Frequently Asked Questions</a> &raquo;</li>
    <li class="right">
        

    <div class="inline-search" style="display: none" role="search">
        <form class="inline-search" action="../search.html" method="get">
          <input placeholder="Quick search" type="text" name="q" />
          <input type="submit" value="Go" />
          <input type="hidden" name="check_keywords" value="yes" />
          <input type="hidden" name="area" value="default" />
        </form>
    </div>
    <script type="text/javascript">$('.inline-search').show(0);</script>
         |
    </li>

      </ul>
    </div>  
    <div class="footer">
    &copy; <a href="../copyright.html">Copyright</a> 2001-2017, Python Software Foundation.
    <br />
    The Python Software Foundation is a non-profit corporation.
    <a href="https://www.python.org/psf/donations/">Please donate.</a>
    <br />
    Last updated on Jan 20, 2017.
    <a href="../bugs.html">Found a bug</a>?
    <br />
    Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.3.3.
    </div>

  </body>
</html>