Ignore:
Timestamp:
Mar 19, 2014, 11:31:01 PM (11 years ago)
Author:
dmik
Message:

python: Merge vendor 2.7.6 to trunk.

Location:
python/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • python/trunk

  • python/trunk/Doc/faq/programming.rst

    r2 r391  
    55===============
    66
    7 .. contents::
     7.. only:: html
     8
     9   .. contents::
    810
    911General Questions
     
    172174
    173175   L2 = []
    174    for i in range[3]:
     176   for i in range(3):
    175177       L2.append(L1[i])
    176178
    177179it is much shorter and far faster to use ::
    178180
    179    L2 = list(L1[:3]) # "list" is redundant if L1 is a list.
     181   L2 = list(L1[:3])  # "list" is redundant if L1 is a list.
    180182
    181183Note that the functionally-oriented built-in functions such as :func:`map`,
     
    184186together::
    185187
    186    >>> zip([1,2,3], [4,5,6])
     188   >>> zip([1, 2, 3], [4, 5, 6])
    187189   [(1, 4), (2, 5), (3, 6)]
    188190
    189191or to compute a number of sines::
    190192
    191    >>> map( math.sin, (1,2,3,4))
    192    [0.841470984808, 0.909297426826, 0.14112000806,   -0.756802495308]
     193   >>> map(math.sin, (1, 2, 3, 4))
     194   [0.841470984808, 0.909297426826, 0.14112000806, -0.756802495308]
    193195
    194196The operation completes very quickly in such cases.
    195197
    196 Other examples include the ``join()`` and ``split()`` methods of string objects.
     198Other examples include the ``join()`` and ``split()`` :ref:`methods
     199of string objects <string-methods>`.
    197200For example if s1..s7 are large (10K+) strings then
    198201``"".join([s1,s2,s3,s4,s5,s6,s7])`` may be far faster than the more obvious
    199202``s1+s2+s3+s4+s5+s6+s7``, since the "summation" will compute many
    200203subexpressions, whereas ``join()`` does all the copying in one pass.  For
    201 manipulating strings, use the ``replace()`` method on string objects. Use
    202 regular expressions only when you're not dealing with constant string patterns.
    203 Consider using the string formatting operations ``string % tuple`` and ``string
    204 % dictionary``.
     204manipulating strings, use the ``replace()`` and the ``format()`` :ref:`methods
     205on string objects <string-methods>`.  Use regular expressions only when you're
     206not dealing with constant string patterns.  You may still use :ref:`the old %
     207operations <string-formatting>` ``string % tuple`` and ``string % dictionary``.
    205208
    206209Be sure to use the :meth:`list.sort` built-in method to do sorting, and see the
     
    212215suppose you have a program that runs slowly and you use the profiler to
    213216determine that a Python function ``ff()`` is being called lots of times.  If you
    214 notice that ``ff ()``::
     217notice that ``ff()``::
    215218
    216219   def ff(x):
     
    333336   11
    334337
    335 In Python3, you can do a similar thing in a nested scope using the
    336 :keyword:`nonlocal` keyword:
    337 
    338 .. doctest::
    339    :options: +SKIP
    340 
    341    >>> def foo():
    342    ...    x = 10
    343    ...    def bar():
    344    ...        nonlocal x
    345    ...        print x
    346    ...        x += 1
    347    ...    bar()
    348    ...    print x
    349    >>> foo()
    350    10
    351    11
    352 
    353338
    354339What are the rules for local and global variables in Python?
     
    370355
    371356
     357Why do lambdas defined in a loop with different values all return the same result?
     358----------------------------------------------------------------------------------
     359
     360Assume you use a for loop to define a few different lambdas (or even plain
     361functions), e.g.::
     362
     363   >>> squares = []
     364   >>> for x in range(5):
     365   ...    squares.append(lambda: x**2)
     366
     367This gives you a list that contains 5 lambdas that calculate ``x**2``.  You
     368might expect that, when called, they would return, respectively, ``0``, ``1``,
     369``4``, ``9``, and ``16``.  However, when you actually try you will see that
     370they all return ``16``::
     371
     372   >>> squares[2]()
     373   16
     374   >>> squares[4]()
     375   16
     376
     377This happens because ``x`` is not local to the lambdas, but is defined in
     378the outer scope, and it is accessed when the lambda is called --- not when it
     379is defined.  At the end of the loop, the value of ``x`` is ``4``, so all the
     380functions now return ``4**2``, i.e. ``16``.  You can also verify this by
     381changing the value of ``x`` and see how the results of the lambdas change::
     382
     383   >>> x = 8
     384   >>> squares[2]()
     385   64
     386
     387In order to avoid this, you need to save the values in variables local to the
     388lambdas, so that they don't rely on the value of the global ``x``::
     389
     390   >>> squares = []
     391   >>> for x in range(5):
     392   ...    squares.append(lambda n=x: n**2)
     393
     394Here, ``n=x`` creates a new variable ``n`` local to the lambda and computed
     395when the lambda is defined so that it has the same value that ``x`` had at
     396that point in the loop.  This means that the value of ``n`` will be ``0``
     397in the first lambda, ``1`` in the second, ``2`` in the third, and so on.
     398Therefore each lambda will now return the correct result::
     399
     400   >>> squares[2]()
     401   4
     402   >>> squares[4]()
     403   16
     404
     405Note that this behaviour is not peculiar to lambdas, but applies to regular
     406functions too.
     407
     408
    372409How do I share global variables across modules?
    373410------------------------------------------------
     
    413450It's good practice if you import modules in the following order:
    414451
    415 1. standard library modules -- e.g. ``sys``, ``os``, ``getopt``, ``re``)
     4521. standard library modules -- e.g. ``sys``, ``os``, ``getopt``, ``re``
    4164532. third-party library modules (anything installed in Python's site-packages
    417454   directory) -- e.g. mx.DateTime, ZODB, PIL.Image, etc.
     
    422459write ``import m2``, even though it's legal.  Write ``from package.sub import
    423460m2`` instead.  Relative imports can lead to a module being initialized twice,
    424 leading to confusing bugs.
     461leading to confusing bugs.  See :pep:`328` for details.
    425462
    426463It is sometimes necessary to move imports to a function or class to avoid
     
    487524
    488525
     526.. index::
     527   single: argument; difference from parameter
     528   single: parameter; difference from argument
     529
     530.. _faq-argument-vs-parameter:
     531
     532What is the difference between arguments and parameters?
     533--------------------------------------------------------
     534
     535:term:`Parameters <parameter>` are defined by the names that appear in a
     536function definition, whereas :term:`arguments <argument>` are the values
     537actually passed to a function when calling it.  Parameters define what types of
     538arguments a function can accept.  For example, given the function definition::
     539
     540   def func(foo, bar=None, **kwargs):
     541       pass
     542
     543*foo*, *bar* and *kwargs* are parameters of ``func``.  However, when calling
     544``func``, for example::
     545
     546   func(42, bar=314, extra=somevar)
     547
     548the values ``42``, ``314``, and ``somevar`` are arguments.
     549
     550
    489551How do I write a function with output parameters (call by reference)?
    490552---------------------------------------------------------------------
     
    650712   b = a
    651713   print b
    652    <__main__.A instance at 016D07CC>
     714   <__main__.A instance at 0x16D07CC>
    653715   print a
    654    <__main__.A instance at 016D07CC>
     716   <__main__.A instance at 0x16D07CC>
    655717
    656718Arguably the class has a name: even though it is bound to two names and invoked
     
    682744
    683745    >>> "a" in "b", "a"
    684     (False, '1')
     746    (False, 'a')
    685747
    686748Since the comma is not an operator, but a separator between expressions the
    687749above is evaluated as if you had entered::
    688750
    689     >>> ("a" in "b"), "a"
     751    ("a" in "b"), "a"
    690752
    691753not::
    692754
    693     >>> "a" in ("5", "a")
     755    "a" in ("b", "a")
    694756
    695757The same is true of the various assignment operators (``=``, ``+=`` etc).  They
     
    709771
    710772For versions previous to 2.5 the answer would be 'No'.
    711 
    712 .. XXX remove rest?
    713 
    714 In many cases you can mimic ``a ? b : c`` with ``a and b or c``, but there's a
    715 flaw: if *b* is zero (or empty, or ``None`` -- anything that tests false) then
    716 *c* will be selected instead.  In many cases you can prove by looking at the
    717 code that this can't happen (e.g. because *b* is a constant or has a type that
    718 can never be false), but in general this can be a problem.
    719 
    720 Tim Peters (who wishes it was Steve Majewski) suggested the following solution:
    721 ``(a and [b] or [c])[0]``.  Because ``[b]`` is a singleton list it is never
    722 false, so the wrong path is never taken; then applying ``[0]`` to the whole
    723 thing gets the *b* or *c* that you really wanted.  Ugly, but it gets you there
    724 in the rare cases where it is really inconvenient to rewrite your code using
    725 'if'.
    726 
    727 The best course is usually to write a simple ``if...else`` statement.  Another
    728 solution is to implement the ``?:`` operator as a function::
    729 
    730    def q(cond, on_true, on_false):
    731        if cond:
    732            if not isfunction(on_true):
    733                return on_true
    734            else:
    735                return apply(on_true)
    736        else:
    737            if not isfunction(on_false):
    738                return on_false
    739            else:
    740                return apply(on_false)
    741 
    742 In most cases you'll pass b and c directly: ``q(a, b, c)``.  To avoid evaluating
    743 b or c when they shouldn't be, encapsulate them within a lambda function, e.g.:
    744 ``q(a, lambda: b, lambda: c)``.
    745 
    746 It has been asked *why* Python has no if-then-else expression.  There are
    747 several answers: many languages do just fine without one; it can easily lead to
    748 less readable code; no sufficiently "Pythonic" syntax has been discovered; a
    749 search of the standard library found remarkably few places where using an
    750 if-then-else expression would make the code more understandable.
    751 
    752 In 2002, :pep:`308` was written proposing several possible syntaxes and the
    753 community was asked to vote on the issue.  The vote was inconclusive.  Most
    754 people liked one of the syntaxes, but also hated other syntaxes; many votes
    755 implied that people preferred no ternary operator rather than having a syntax
    756 they hated.
    757773
    758774
     
    768784
    769785   # First 10 Fibonacci numbers
    770    print map(lambda x,f=lambda x,f:(x<=1) or (f(x-1,f)+f(x-2,f)): f(x,f),
     786   print map(lambda x,f=lambda x,f:(f(x-1,f)+f(x-2,f)) if x>1 else 1: f(x,f),
    771787   range(10))
    772788
     
    794810------------------------------------------------
    795811
    796 To specify an octal digit, precede the octal value with a zero.  For example, to
    797 set the variable "a" to the octal value "10" (8 in decimal), type::
    798 
    799    >>> a = 010
     812To specify an octal digit, precede the octal value with a zero, and then a lower
     813or uppercase "o".  For example, to set the variable "a" to the octal value "10"
     814(8 in decimal), type::
     815
     816   >>> a = 0o10
    800817   >>> a
    801818   8
     
    813830
    814831
    815 Why does -22 / 10 return -3?
    816 ----------------------------
     832Why does -22 // 10 return -3?
     833-----------------------------
    817834
    818835It's primarily driven by the desire that ``i % j`` have the same sign as ``j``.
    819836If you want that, and also want::
    820837
    821     i == (i / j) * j + (i % j)
     838    i == (i // j) * j + (i % j)
    822839
    823840then integer division has to return the floor.  C also requires that identity to
    824 hold, and then compilers that truncate ``i / j`` need to make ``i % j`` have the
    825 same sign as ``i``.
     841hold, and then compilers that truncate ``i // j`` need to make ``i % j`` have
     842the same sign as ``i``.
    826843
    827844There are few real use cases for ``i % j`` when ``j`` is negative.  When ``j``
     
    830847ago?  ``-190 % 12 == 2`` is useful; ``-190 % 12 == -10`` is a bug waiting to
    831848bite.
     849
     850.. note::
     851
     852   On Python 2, ``a / b`` returns the same as ``a // b`` if
     853   ``__future__.division`` is not in effect.  This is also known as "classic"
     854   division.
    832855
    833856
     
    862885To convert, e.g., the number 144 to the string '144', use the built-in type
    863886constructor :func:`str`.  If you want a hexadecimal or octal representation, use
    864 the built-in functions ``hex()`` or ``oct()``.  For fancy formatting, use
    865 :ref:`the % operator <string-formatting>` on strings, e.g. ``"%04d" % 144``
    866 yields ``'0144'`` and ``"%.3f" % (1/3.0)`` yields ``'0.333'``.  See the library
    867 reference manual for details.
     887the built-in functions :func:`hex` or :func:`oct`.  For fancy formatting, see
     888the :ref:`formatstrings` section, e.g. ``"{:04d}".format(144)`` yields
     889``'0144'`` and ``"{:.3f}".format(1/3)`` yields ``'0.333'``.  You may also use
     890:ref:`the % operator <string-formatting>` on strings.  See the library reference
     891manual for details.
    868892
    869893
     
    874898ability, try converting the string to a list or use the array module::
    875899
     900   >>> import io
    876901   >>> s = "Hello, world"
    877902   >>> a = list(s)
     
    887912   array('c', 'Hello, world')
    888913   >>> a[0] = 'y' ; print a
    889    array('c', 'yello world')
     914   array('c', 'yello, world')
    890915   >>> a.tostring()
    891916   'yello, world'
     
    954979
    955980Starting with Python 2.2, you can use ``S.rstrip("\r\n")`` to remove all
    956 occurences of any line terminator from the end of the string ``S`` without
     981occurrences of any line terminator from the end of the string ``S`` without
    957982removing other trailing whitespace.  If the string ``S`` represents more than
    958983one line, with several empty lines at the end, the line terminators for all the
     
    963988   ...          "\r\n")
    964989   >>> lines.rstrip("\n\r")
    965    "line 1 "
     990   'line 1 '
    966991
    967992Since this is typically only desired when reading text one line at a time, using
    968993``S.rstrip()`` this way works well.
    969994
    970 For older versions of Python, There are two partial substitutes:
     995For older versions of Python, there are two partial substitutes:
    971996
    972997- If you want to remove all trailing whitespace, use the ``rstrip()`` method of
     
    9891014if the line uses something other than whitespace as a separator.
    9901015
    991 For more complicated input parsing, regular expressions more powerful than C's
    992 :cfunc:`sscanf` and better suited for the task.
     1016For more complicated input parsing, regular expressions are more powerful
     1017than C's :c:func:`sscanf` and better suited for the task.
    9931018
    9941019
     
    10941119list, deleting duplicates as you go::
    10951120
    1096    if List:
    1097        List.sort()
    1098        last = List[-1]
    1099        for i in range(len(List)-2, -1, -1):
    1100            if last == List[i]:
    1101                del List[i]
     1121   if mylist:
     1122       mylist.sort()
     1123       last = mylist[-1]
     1124       for i in range(len(mylist)-2, -1, -1):
     1125           if last == mylist[i]:
     1126               del mylist[i]
    11021127           else:
    1103                last = List[i]
     1128               last = mylist[i]
    11041129
    11051130If all elements of the list may be used as dictionary keys (i.e. they are all
     
    11071132
    11081133   d = {}
    1109    for x in List:
    1110        d[x] = x
    1111    List = d.values()
     1134   for x in mylist:
     1135       d[x] = 1
     1136   mylist = list(d.keys())
    11121137
    11131138In Python 2.5 and later, the following is possible instead::
    11141139
    1115    List = list(set(List))
     1140   mylist = list(set(mylist))
    11161141
    11171142This converts the list into a set, thereby removing duplicates, and then back
     
    11491174You probably tried to make a multidimensional array like this::
    11501175
    1151    A = [[None] * 2] * 3
     1176   >>> A = [[None] * 2] * 3
    11521177
    11531178This looks correct if you print it::
     
    11811206
    11821207Or, you can use an extension that provides a matrix datatype; `Numeric Python
    1183 <http://numpy.scipy.org/>`_ is the best known.
     1208<http://www.numpy.org/>`_ is the best known.
    11841209
    11851210
     
    11891214Use a list comprehension::
    11901215
    1191    result = [obj.method() for obj in List]
     1216   result = [obj.method() for obj in mylist]
    11921217
    11931218More generically, you can try the following function::
     
    12001225
    12011226
     1227Why does a_tuple[i] += ['item'] raise an exception when the addition works?
     1228---------------------------------------------------------------------------
     1229
     1230This is because of a combination of the fact that augmented assignment
     1231operators are *assignment* operators, and the difference between mutable and
     1232immutable objects in Python.
     1233
     1234This discussion applies in general when augmented assignment operators are
     1235applied to elements of a tuple that point to mutable objects, but we'll use
     1236a ``list`` and ``+=`` as our exemplar.
     1237
     1238If you wrote::
     1239
     1240   >>> a_tuple = (1, 2)
     1241   >>> a_tuple[0] += 1
     1242   Traceback (most recent call last):
     1243      ...
     1244   TypeError: 'tuple' object does not support item assignment
     1245
     1246The reason for the exception should be immediately clear: ``1`` is added to the
     1247object ``a_tuple[0]`` points to (``1``), producing the result object, ``2``,
     1248but when we attempt to assign the result of the computation, ``2``, to element
     1249``0`` of the tuple, we get an error because we can't change what an element of
     1250a tuple points to.
     1251
     1252Under the covers, what this augmented assignment statement is doing is
     1253approximately this::
     1254
     1255   >>> result = a_tuple[0] + 1
     1256   >>> a_tuple[0] = result
     1257   Traceback (most recent call last):
     1258     ...
     1259   TypeError: 'tuple' object does not support item assignment
     1260
     1261It is the assignment part of the operation that produces the error, since a
     1262tuple is immutable.
     1263
     1264When you write something like::
     1265
     1266   >>> a_tuple = (['foo'], 'bar')
     1267   >>> a_tuple[0] += ['item']
     1268   Traceback (most recent call last):
     1269     ...
     1270   TypeError: 'tuple' object does not support item assignment
     1271
     1272The exception is a bit more surprising, and even more surprising is the fact
     1273that even though there was an error, the append worked::
     1274
     1275    >>> a_tuple[0]
     1276    ['foo', 'item']
     1277
     1278To see why this happens, you need to know that (a) if an object implements an
     1279``__iadd__`` magic method, it gets called when the ``+=`` augmented assignment
     1280is executed, and its return value is what gets used in the assignment statement;
     1281and (b) for lists, ``__iadd__`` is equivalent to calling ``extend`` on the list
     1282and returning the list.  That's why we say that for lists, ``+=`` is a
     1283"shorthand" for ``list.extend``::
     1284
     1285    >>> a_list = []
     1286    >>> a_list += [1]
     1287    >>> a_list
     1288    [1]
     1289
     1290This is equivalent to::
     1291
     1292    >>> result = a_list.__iadd__([1])
     1293    >>> a_list = result
     1294
     1295The object pointed to by a_list has been mutated, and the pointer to the
     1296mutated object is assigned back to ``a_list``.  The end result of the
     1297assignment is a no-op, since it is a pointer to the same object that ``a_list``
     1298was previously pointing to, but the assignment still happens.
     1299
     1300Thus, in our tuple example what is happening is equivalent to::
     1301
     1302   >>> result = a_tuple[0].__iadd__(['item'])
     1303   >>> a_tuple[0] = result
     1304   Traceback (most recent call last):
     1305     ...
     1306   TypeError: 'tuple' object does not support item assignment
     1307
     1308The ``__iadd__`` succeeds, and thus the list is extended, but even though
     1309``result`` points to the same object that ``a_tuple[0]`` already points to,
     1310that final assignment still results in an error, because tuples are immutable.
     1311
     1312
    12021313Dictionaries
    12031314============
     
    12141325be presented in order sorted by the key.
    12151326
    1216 A more complicated solution is to subclass ``UserDict.UserDict`` to create a
     1327A more complicated solution is to subclass ``dict`` to create a
    12171328``SortedDict`` class that prints itself in a predictable order.  Here's one
    12181329simpleminded implementation of such a class::
    12191330
    1220    import UserDict, string
    1221 
    1222    class SortedDict(UserDict.UserDict):
     1331   class SortedDict(dict):
    12231332       def __repr__(self):
    1224            result = []
    1225            append = result.append
    1226            keys = self.data.keys()
    1227            keys.sort()
    1228            for k in keys:
    1229                append("%s: %s" % (`k`, `self.data[k]`))
    1230            return "{%s}" % string.join(result, ", ")
    1231 
    1232      __str__ = __repr__
     1333           keys = sorted(self.keys())
     1334           result = ("{!r}: {!r}".format(k, self[k]) for k in keys)
     1335           return "{{{}}}".format(", ".join(result))
     1336
     1337       __str__ = __repr__
    12331338
    12341339This will work for many common situations you might encounter, though it's far
     
    12521357strings by their uppercase values::
    12531358
    1254   tmp1 = [(x.upper(), x) for x in L] # Schwartzian transform
     1359  tmp1 = [(x.upper(), x) for x in L]  # Schwartzian transform
    12551360  tmp1.sort()
    12561361  Usorted = [x[1] for x in tmp1]
     
    12591364each string::
    12601365
    1261   tmp2 = [(int(s[10:15]), s) for s in L] # Schwartzian transform
     1366  tmp2 = [(int(s[10:15]), s) for s in L]  # Schwartzian transform
    12621367  tmp2.sort()
    12631368  Isorted = [x[1] for x in tmp2]
     
    12961401An alternative for the last step is::
    12971402
    1298    result = []
    1299    for p in pairs: result.append(p[1])
     1403   >>> result = []
     1404   >>> for p in pairs: result.append(p[1])
    13001405
    13011406If you find this more legible, you might prefer to use this instead of the final
     
    13651470that does something::
    13661471
    1367    def search (obj):
     1472   def search(obj):
    13681473       if isinstance(obj, Mailbox):
    13691474           # ... code to search a mailbox
     
    14681573-----------------------------------------------------------
    14691574
    1470 Static data (in the sense of C++ or Java) is easy; static methods (again in the
    1471 sense of C++ or Java) are not supported directly.
     1575Both static data and static methods (in the sense of C++ or Java) are supported
     1576in Python.
    14721577
    14731578For static data, simply define a class attribute.  To assign a new value to the
     
    14881593
    14891594Caution: within a method of C, an assignment like ``self.count = 42`` creates a
    1490 new and unrelated instance vrbl named "count" in ``self``'s own dict.  Rebinding
    1491 of a class-static data name must always specify the class whether inside a
    1492 method or not::
     1595new and unrelated instance named "count" in ``self``'s own dict.  Rebinding of a
     1596class-static data name must always specify the class whether inside a method or
     1597not::
    14931598
    14941599   C.count = 314
     
    16201725
    16211726
     1727Why does the result of ``id()`` appear to be not unique?
     1728--------------------------------------------------------
     1729
     1730The :func:`id` builtin returns an integer that is guaranteed to be unique during
     1731the lifetime of the object.  Since in CPython, this is the object's memory
     1732address, it happens frequently that after an object is deleted from memory, the
     1733next freshly created object is allocated at the same position in memory.  This
     1734is illustrated by this example:
     1735
     1736>>> id(1000)
     173713901272
     1738>>> id(2000)
     173913901272
     1740
     1741The two ids belong to different integer objects that are created before, and
     1742deleted immediately after execution of the ``id()`` call.  To be sure that
     1743objects whose id you want to examine are still alive, create another reference
     1744to the object:
     1745
     1746>>> a = 1000; b = 2000
     1747>>> id(a)
     174813901272
     1749>>> id(b)
     175013891296
     1751
     1752
    16221753Modules
    16231754=======
     
    16371768directory.
    16381769
    1639 Running Python on a top level script is not considered an import and no ``.pyc``
    1640 will be created.  For example, if you have a top-level module ``abc.py`` that
    1641 imports another module ``xyz.py``, when you run abc, ``xyz.pyc`` will be created
    1642 since xyz is imported, but no ``abc.pyc`` file will be created since ``abc.py``
    1643 isn't being imported.
    1644 
    1645 If you need to create abc.pyc -- that is, to create a .pyc file for a module
     1770Running Python on a top level script is not considered an import and no
     1771``.pyc`` will be created.  For example, if you have a top-level module
     1772``foo.py`` that imports another module ``xyz.py``, when you run ``foo``,
     1773``xyz.pyc`` will be created since ``xyz`` is imported, but no ``foo.pyc`` file
     1774will be created since ``foo.py`` isn't being imported.
     1775
     1776If you need to create ``foo.pyc`` -- that is, to create a ``.pyc`` file for a module
    16461777that is not imported -- you can, using the :mod:`py_compile` and
    16471778:mod:`compileall` modules.
     
    16511782
    16521783   >>> import py_compile
    1653    >>> py_compile.compile('abc.py')
    1654 
    1655 This will write the ``.pyc`` to the same location as ``abc.py`` (or you can
     1784   >>> py_compile.compile('foo.py')                 # doctest: +SKIP
     1785
     1786This will write the ``.pyc`` to the same location as ``foo.py`` (or you can
    16561787override that with the optional parameter ``cfile``).
    16571788
Note: See TracChangeset for help on using the changeset viewer.