mirror of https://github.com/python/cpython
Merged revisions 74764 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k ........ r74764 | ezio.melotti | 2009-09-13 10:54:02 +0300 (Sun, 13 Sep 2009) | 1 line fixed more examples that were using u"", print without () and unicode/str instead of str/bytes ........
This commit is contained in:
parent
f388053649
commit
713e042152
|
@ -52,7 +52,7 @@ The following exceptions are only used as base classes for other exceptions.
|
||||||
|
|
||||||
The base class for all built-in exceptions. It is not meant to be directly
|
The base class for all built-in exceptions. It is not meant to be directly
|
||||||
inherited by user-defined classes (for that use :exc:`Exception`). If
|
inherited by user-defined classes (for that use :exc:`Exception`). If
|
||||||
:func:`str` or :func:`unicode` is called on an instance of this class, the
|
:func:`bytes` or :func:`str` is called on an instance of this class, the
|
||||||
representation of the argument(s) to the instance are returned or the empty
|
representation of the argument(s) to the instance are returned or the empty
|
||||||
string when there were no arguments. All arguments are stored in :attr:`args`
|
string when there were no arguments. All arguments are stored in :attr:`args`
|
||||||
as a tuple.
|
as a tuple.
|
||||||
|
|
|
@ -118,7 +118,7 @@ Basic Usage
|
||||||
file-like object).
|
file-like object).
|
||||||
|
|
||||||
If *skipkeys* is ``True`` (default: ``False``), then dict keys that are not
|
If *skipkeys* is ``True`` (default: ``False``), then dict keys that are not
|
||||||
of a basic type (:class:`str`, :class:`unicode`, :class:`int`,
|
of a basic type (:class:`bytes`, :class:`str`, :class:`int`,
|
||||||
:class:`float`, :class:`bool`, ``None``) will be skipped instead of raising a
|
:class:`float`, :class:`bool`, ``None``) will be skipped instead of raising a
|
||||||
:exc:`TypeError`.
|
:exc:`TypeError`.
|
||||||
|
|
||||||
|
@ -201,13 +201,13 @@ Basic Usage
|
||||||
|
|
||||||
.. function:: loads(s, encoding=None, cls=None, object_hook=None, parse_float=None, parse_int=None, parse_constant=None, object_pairs_hook=None, **kw)
|
.. function:: loads(s, encoding=None, cls=None, object_hook=None, parse_float=None, parse_int=None, parse_constant=None, object_pairs_hook=None, **kw)
|
||||||
|
|
||||||
Deserialize *s* (a :class:`str` or :class:`unicode` instance containing a JSON
|
Deserialize *s* (a :class:`bytes` or :class:`str` instance containing a JSON
|
||||||
document) to a Python object.
|
document) to a Python object.
|
||||||
|
|
||||||
If *s* is a :class:`str` instance and is encoded with an ASCII based encoding
|
If *s* is a :class:`bytes` instance and is encoded with an ASCII based encoding
|
||||||
other than UTF-8 (e.g. latin-1), then an appropriate *encoding* name must be
|
other than UTF-8 (e.g. latin-1), then an appropriate *encoding* name must be
|
||||||
specified. Encodings that are not ASCII based (such as UCS-2) are not
|
specified. Encodings that are not ASCII based (such as UCS-2) are not
|
||||||
allowed and should be decoded to :class:`unicode` first.
|
allowed and should be decoded to :class:`str` first.
|
||||||
|
|
||||||
The other arguments have the same meaning as in :func:`dump`.
|
The other arguments have the same meaning as in :func:`dump`.
|
||||||
|
|
||||||
|
|
|
@ -77,14 +77,14 @@ To show the individual process IDs involved, here is an expanded example::
|
||||||
import os
|
import os
|
||||||
|
|
||||||
def info(title):
|
def info(title):
|
||||||
print title
|
print(title)
|
||||||
print 'module name:', __name__
|
print('module name:', __name__)
|
||||||
print 'parent process:', os.getppid()
|
print('parent process:', os.getppid())
|
||||||
print 'process id:', os.getpid()
|
print('process id:', os.getpid())
|
||||||
|
|
||||||
def f(name):
|
def f(name):
|
||||||
info('function f')
|
info('function f')
|
||||||
print 'hello', name
|
print('hello', name)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
info('main line')
|
info('main line')
|
||||||
|
@ -279,10 +279,10 @@ For example::
|
||||||
return x*x
|
return x*x
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
pool = Pool(processes=4) # start 4 worker processes
|
pool = Pool(processes=4) # start 4 worker processes
|
||||||
result = pool.apply_async(f, [10]) # evaluate "f(10)" asynchronously
|
result = pool.apply_async(f, [10]) # evaluate "f(10)" asynchronously
|
||||||
print result.get(timeout=1) # prints "100" unless your computer is *very* slow
|
print(result.get(timeout=1)) # prints "100" unless your computer is *very* slow
|
||||||
print pool.map(f, range(10)) # prints "[0, 1, 4,..., 81]"
|
print(pool.map(f, range(10))) # prints "[0, 1, 4,..., 81]"
|
||||||
|
|
||||||
|
|
||||||
Reference
|
Reference
|
||||||
|
|
|
@ -20,7 +20,7 @@ top level object is a dictionary.
|
||||||
|
|
||||||
Values can be strings, integers, floats, booleans, tuples, lists, dictionaries
|
Values can be strings, integers, floats, booleans, tuples, lists, dictionaries
|
||||||
(but only with string keys), :class:`Data` or :class:`datetime.datetime`
|
(but only with string keys), :class:`Data` or :class:`datetime.datetime`
|
||||||
objects. String values (including dictionary keys) may be unicode strings --
|
objects. String values (including dictionary keys) have to be unicode strings --
|
||||||
they will be written out as UTF-8.
|
they will be written out as UTF-8.
|
||||||
|
|
||||||
The ``<data>`` plist type is supported through the :class:`Data` class. This is
|
The ``<data>`` plist type is supported through the :class:`Data` class. This is
|
||||||
|
@ -83,22 +83,20 @@ Examples
|
||||||
Generating a plist::
|
Generating a plist::
|
||||||
|
|
||||||
pl = dict(
|
pl = dict(
|
||||||
aString="Doodah",
|
aString = "Doodah",
|
||||||
aList=["A", "B", 12, 32.1, [1, 2, 3]],
|
aList = ["A", "B", 12, 32.1, [1, 2, 3]],
|
||||||
aFloat = 0.1,
|
aFloat = 0.1,
|
||||||
anInt = 728,
|
anInt = 728,
|
||||||
aDict=dict(
|
aDict = dict(
|
||||||
anotherString="<hello & hi there!>",
|
anotherString = "<hello & hi there!>",
|
||||||
aUnicodeValue=u'M\xe4ssig, Ma\xdf',
|
aThirdString = "M\xe4ssig, Ma\xdf",
|
||||||
aTrueValue=True,
|
aTrueValue = True,
|
||||||
aFalseValue=False,
|
aFalseValue = False,
|
||||||
),
|
),
|
||||||
someData = Data("<binary gunk>"),
|
someData = Data("<binary gunk>"),
|
||||||
someMoreData = Data("<lots of binary gunk>" * 10),
|
someMoreData = Data("<lots of binary gunk>" * 10),
|
||||||
aDate = datetime.datetime.fromtimestamp(time.mktime(time.gmtime())),
|
aDate = datetime.datetime.fromtimestamp(time.mktime(time.gmtime())),
|
||||||
)
|
)
|
||||||
# unicode keys are possible, but a little awkward to use:
|
|
||||||
pl[u'\xc5benraa'] = "That was a unicode key."
|
|
||||||
writePlist(pl, fileName)
|
writePlist(pl, fileName)
|
||||||
|
|
||||||
Parsing a plist::
|
Parsing a plist::
|
||||||
|
|
|
@ -311,12 +311,12 @@ SSLSocket Objects
|
||||||
name-value pairs::
|
name-value pairs::
|
||||||
|
|
||||||
{'notAfter': 'Feb 16 16:54:50 2013 GMT',
|
{'notAfter': 'Feb 16 16:54:50 2013 GMT',
|
||||||
'subject': ((('countryName', u'US'),),
|
'subject': ((('countryName', 'US'),),
|
||||||
(('stateOrProvinceName', u'Delaware'),),
|
(('stateOrProvinceName', 'Delaware'),),
|
||||||
(('localityName', u'Wilmington'),),
|
(('localityName', 'Wilmington'),),
|
||||||
(('organizationName', u'Python Software Foundation'),),
|
(('organizationName', 'Python Software Foundation'),),
|
||||||
(('organizationalUnitName', u'SSL'),),
|
(('organizationalUnitName', 'SSL'),),
|
||||||
(('commonName', u'somemachine.python.org'),))}
|
(('commonName', 'somemachine.python.org'),))}
|
||||||
|
|
||||||
If the ``binary_form`` parameter is :const:`True`, and a
|
If the ``binary_form`` parameter is :const:`True`, and a
|
||||||
certificate was provided, this method returns the DER-encoded form
|
certificate was provided, this method returns the DER-encoded form
|
||||||
|
@ -522,20 +522,20 @@ As of September 6, 2007, the certificate printed by this program
|
||||||
looked like this::
|
looked like this::
|
||||||
|
|
||||||
{'notAfter': 'May 8 23:59:59 2009 GMT',
|
{'notAfter': 'May 8 23:59:59 2009 GMT',
|
||||||
'subject': ((('serialNumber', u'2497886'),),
|
'subject': ((('serialNumber', '2497886'),),
|
||||||
(('1.3.6.1.4.1.311.60.2.1.3', u'US'),),
|
(('1.3.6.1.4.1.311.60.2.1.3', 'US'),),
|
||||||
(('1.3.6.1.4.1.311.60.2.1.2', u'Delaware'),),
|
(('1.3.6.1.4.1.311.60.2.1.2', 'Delaware'),),
|
||||||
(('countryName', u'US'),),
|
(('countryName', 'US'),),
|
||||||
(('postalCode', u'94043'),),
|
(('postalCode', '94043'),),
|
||||||
(('stateOrProvinceName', u'California'),),
|
(('stateOrProvinceName', 'California'),),
|
||||||
(('localityName', u'Mountain View'),),
|
(('localityName', 'Mountain View'),),
|
||||||
(('streetAddress', u'487 East Middlefield Road'),),
|
(('streetAddress', '487 East Middlefield Road'),),
|
||||||
(('organizationName', u'VeriSign, Inc.'),),
|
(('organizationName', 'VeriSign, Inc.'),),
|
||||||
(('organizationalUnitName',
|
(('organizationalUnitName',
|
||||||
u'Production Security Services'),),
|
'Production Security Services'),),
|
||||||
(('organizationalUnitName',
|
(('organizationalUnitName',
|
||||||
u'Terms of use at www.verisign.com/rpa (c)06'),),
|
'Terms of use at www.verisign.com/rpa (c)06'),),
|
||||||
(('commonName', u'www.verisign.com'),))}
|
(('commonName', 'www.verisign.com'),))}
|
||||||
|
|
||||||
which is a fairly poorly-formed ``subject`` field.
|
which is a fairly poorly-formed ``subject`` field.
|
||||||
|
|
||||||
|
|
|
@ -510,13 +510,13 @@ Return code handling translates as follows::
|
||||||
...
|
...
|
||||||
rc = pipe.close()
|
rc = pipe.close()
|
||||||
if rc != None and rc % 256:
|
if rc != None and rc % 256:
|
||||||
print "There were some errors"
|
print("There were some errors")
|
||||||
==>
|
==>
|
||||||
process = Popen(cmd, 'w', stdin=PIPE)
|
process = Popen(cmd, 'w', stdin=PIPE)
|
||||||
...
|
...
|
||||||
process.stdin.close()
|
process.stdin.close()
|
||||||
if process.wait() != 0:
|
if process.wait() != 0:
|
||||||
print "There were some errors"
|
print("There were some errors")
|
||||||
|
|
||||||
|
|
||||||
Replacing functions from the :mod:`popen2` module
|
Replacing functions from the :mod:`popen2` module
|
||||||
|
|
|
@ -1228,7 +1228,7 @@ option. If you don't know the class name of a widget, use the method
|
||||||
|
|
||||||
from tkinter import ttk
|
from tkinter import ttk
|
||||||
|
|
||||||
print ttk.Style().lookup("TButton", "font")
|
print(ttk.Style().lookup("TButton", "font"))
|
||||||
|
|
||||||
|
|
||||||
.. method:: layout(style[, layoutspec=None])
|
.. method:: layout(style[, layoutspec=None])
|
||||||
|
|
|
@ -645,7 +645,7 @@ Tell Turtle's state
|
||||||
>>> turtle.forward(100)
|
>>> turtle.forward(100)
|
||||||
>>> turtle.pos()
|
>>> turtle.pos()
|
||||||
(64.28,76.60)
|
(64.28,76.60)
|
||||||
>>> print turtle.xcor()
|
>>> print(turtle.xcor())
|
||||||
64.2787609687
|
64.2787609687
|
||||||
|
|
||||||
|
|
||||||
|
@ -658,9 +658,9 @@ Tell Turtle's state
|
||||||
>>> turtle.home()
|
>>> turtle.home()
|
||||||
>>> turtle.left(60)
|
>>> turtle.left(60)
|
||||||
>>> turtle.forward(100)
|
>>> turtle.forward(100)
|
||||||
>>> print turtle.pos()
|
>>> print(turtle.pos())
|
||||||
(50.00,86.60)
|
(50.00,86.60)
|
||||||
>>> print turtle.ycor()
|
>>> print(turtle.ycor())
|
||||||
86.6025403784
|
86.6025403784
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -146,7 +146,7 @@ Examples:
|
||||||
|
|
||||||
>>> import unicodedata
|
>>> import unicodedata
|
||||||
>>> unicodedata.lookup('LEFT CURLY BRACKET')
|
>>> unicodedata.lookup('LEFT CURLY BRACKET')
|
||||||
u'{'
|
'{'
|
||||||
>>> unicodedata.name('/')
|
>>> unicodedata.name('/')
|
||||||
'SOLIDUS'
|
'SOLIDUS'
|
||||||
>>> unicodedata.decimal('9')
|
>>> unicodedata.decimal('9')
|
||||||
|
|
|
@ -130,12 +130,12 @@ This module offers the following functions:
|
||||||
+-------+--------------------------------------------+
|
+-------+--------------------------------------------+
|
||||||
|
|
||||||
|
|
||||||
.. function:: ExpandEnvironmentStrings(unicode)
|
.. function:: ExpandEnvironmentStrings(str)
|
||||||
|
|
||||||
Expands environment strings %NAME% in unicode string like const:`REG_EXPAND_SZ`::
|
Expands environment strings %NAME% in unicode string like :const:`REG_EXPAND_SZ`::
|
||||||
|
|
||||||
>>> ExpandEnvironmentStrings(u"%windir%")
|
>>> ExpandEnvironmentStrings('%windir%')
|
||||||
u"C:\\Windows"
|
'C:\\Windows'
|
||||||
|
|
||||||
|
|
||||||
.. function:: FlushKey(key)
|
.. function:: FlushKey(key)
|
||||||
|
|
Loading…
Reference in New Issue