mirror of https://github.com/python/cpython
gh-99087: Add missing newline for prompts in docs (GH-98993)
Add newline for prompts so copying to REPL does not cause errors.
This commit is contained in:
parent
3e06b5030b
commit
286e3c76a9
|
@ -158,6 +158,7 @@ And a function to display the chores for a given day::
|
||||||
... for chore, days in chores.items():
|
... for chore, days in chores.items():
|
||||||
... if day in days:
|
... if day in days:
|
||||||
... print(chore)
|
... print(chore)
|
||||||
|
...
|
||||||
>>> show_chores(chores_for_ethan, Weekday.SATURDAY)
|
>>> show_chores(chores_for_ethan, Weekday.SATURDAY)
|
||||||
answer SO questions
|
answer SO questions
|
||||||
|
|
||||||
|
@ -712,6 +713,7 @@ It is also possible to name the combinations::
|
||||||
... W = 2
|
... W = 2
|
||||||
... X = 1
|
... X = 1
|
||||||
... RWX = 7
|
... RWX = 7
|
||||||
|
...
|
||||||
>>> Perm.RWX
|
>>> Perm.RWX
|
||||||
<Perm.RWX: 7>
|
<Perm.RWX: 7>
|
||||||
>>> ~Perm.RWX
|
>>> ~Perm.RWX
|
||||||
|
|
|
@ -565,6 +565,7 @@ arguments they contain. For example::
|
||||||
|
|
||||||
>>> with open('args.txt', 'w', encoding=sys.getfilesystemencoding()) as fp:
|
>>> with open('args.txt', 'w', encoding=sys.getfilesystemencoding()) as fp:
|
||||||
... fp.write('-f\nbar')
|
... fp.write('-f\nbar')
|
||||||
|
...
|
||||||
>>> parser = argparse.ArgumentParser(fromfile_prefix_chars='@')
|
>>> parser = argparse.ArgumentParser(fromfile_prefix_chars='@')
|
||||||
>>> parser.add_argument('-f')
|
>>> parser.add_argument('-f')
|
||||||
>>> parser.parse_args(['-f', 'foo', '@args.txt'])
|
>>> parser.parse_args(['-f', 'foo', '@args.txt'])
|
||||||
|
|
|
@ -320,9 +320,11 @@ Writing and reading a bzip2-compressed file in binary mode:
|
||||||
>>> with bz2.open("myfile.bz2", "wb") as f:
|
>>> with bz2.open("myfile.bz2", "wb") as f:
|
||||||
... # Write compressed data to file
|
... # Write compressed data to file
|
||||||
... unused = f.write(data)
|
... unused = f.write(data)
|
||||||
|
...
|
||||||
>>> with bz2.open("myfile.bz2", "rb") as f:
|
>>> with bz2.open("myfile.bz2", "rb") as f:
|
||||||
... # Decompress data from file
|
... # Decompress data from file
|
||||||
... content = f.read()
|
... content = f.read()
|
||||||
|
...
|
||||||
>>> content == data # Check equality to original object after round-trip
|
>>> content == data # Check equality to original object after round-trip
|
||||||
True
|
True
|
||||||
|
|
||||||
|
|
|
@ -229,6 +229,7 @@ For example::
|
||||||
>>> cnt = Counter()
|
>>> cnt = Counter()
|
||||||
>>> for word in ['red', 'blue', 'red', 'green', 'blue', 'blue']:
|
>>> for word in ['red', 'blue', 'red', 'green', 'blue', 'blue']:
|
||||||
... cnt[word] += 1
|
... cnt[word] += 1
|
||||||
|
...
|
||||||
>>> cnt
|
>>> cnt
|
||||||
Counter({'blue': 3, 'red': 2, 'green': 1})
|
Counter({'blue': 3, 'red': 2, 'green': 1})
|
||||||
|
|
||||||
|
@ -818,6 +819,7 @@ zero):
|
||||||
|
|
||||||
>>> def constant_factory(value):
|
>>> def constant_factory(value):
|
||||||
... return lambda: value
|
... return lambda: value
|
||||||
|
...
|
||||||
>>> d = defaultdict(constant_factory('<missing>'))
|
>>> d = defaultdict(constant_factory('<missing>'))
|
||||||
>>> d.update(name='John', action='ran')
|
>>> d.update(name='John', action='ran')
|
||||||
>>> '%(name)s %(action)s to %(object)s' % d
|
>>> '%(name)s %(action)s to %(object)s' % d
|
||||||
|
|
|
@ -765,6 +765,7 @@ Example of counting days to an event::
|
||||||
>>> my_birthday = date(today.year, 6, 24)
|
>>> my_birthday = date(today.year, 6, 24)
|
||||||
>>> if my_birthday < today:
|
>>> if my_birthday < today:
|
||||||
... my_birthday = my_birthday.replace(year=today.year + 1)
|
... my_birthday = my_birthday.replace(year=today.year + 1)
|
||||||
|
...
|
||||||
>>> my_birthday
|
>>> my_birthday
|
||||||
datetime.date(2008, 6, 24)
|
datetime.date(2008, 6, 24)
|
||||||
>>> time_to_birthday = abs(my_birthday - today)
|
>>> time_to_birthday = abs(my_birthday - today)
|
||||||
|
|
|
@ -2057,6 +2057,7 @@ to handle the :meth:`quantize` step:
|
||||||
|
|
||||||
>>> def mul(x, y, fp=TWOPLACES):
|
>>> def mul(x, y, fp=TWOPLACES):
|
||||||
... return (x * y).quantize(fp)
|
... return (x * y).quantize(fp)
|
||||||
|
...
|
||||||
>>> def div(x, y, fp=TWOPLACES):
|
>>> def div(x, y, fp=TWOPLACES):
|
||||||
... return (x / y).quantize(fp)
|
... return (x / y).quantize(fp)
|
||||||
|
|
||||||
|
|
|
@ -351,6 +351,7 @@ The fine print:
|
||||||
|
|
||||||
>>> def f(x):
|
>>> def f(x):
|
||||||
... r'''Backslashes in a raw docstring: m\n'''
|
... r'''Backslashes in a raw docstring: m\n'''
|
||||||
|
...
|
||||||
>>> print(f.__doc__)
|
>>> print(f.__doc__)
|
||||||
Backslashes in a raw docstring: m\n
|
Backslashes in a raw docstring: m\n
|
||||||
|
|
||||||
|
@ -360,6 +361,7 @@ The fine print:
|
||||||
|
|
||||||
>>> def f(x):
|
>>> def f(x):
|
||||||
... '''Backslashes in a raw docstring: m\\n'''
|
... '''Backslashes in a raw docstring: m\\n'''
|
||||||
|
...
|
||||||
>>> print(f.__doc__)
|
>>> print(f.__doc__)
|
||||||
Backslashes in a raw docstring: m\n
|
Backslashes in a raw docstring: m\n
|
||||||
|
|
||||||
|
|
|
@ -97,6 +97,7 @@ file on disk and pass it to the system ``sendmail`` program on a Unix system:
|
||||||
>>> from subprocess import Popen, PIPE
|
>>> from subprocess import Popen, PIPE
|
||||||
>>> with open('mymsg.txt', 'rb') as f:
|
>>> with open('mymsg.txt', 'rb') as f:
|
||||||
... msg = message_from_binary_file(f, policy=policy.default)
|
... msg = message_from_binary_file(f, policy=policy.default)
|
||||||
|
...
|
||||||
>>> p = Popen(['sendmail', msg['To'].addresses[0]], stdin=PIPE)
|
>>> p = Popen(['sendmail', msg['To'].addresses[0]], stdin=PIPE)
|
||||||
>>> g = BytesGenerator(p.stdin, policy=msg.policy.clone(linesep='\r\n'))
|
>>> g = BytesGenerator(p.stdin, policy=msg.policy.clone(linesep='\r\n'))
|
||||||
>>> g.flatten(msg)
|
>>> g.flatten(msg)
|
||||||
|
|
|
@ -292,6 +292,7 @@ Data Types
|
||||||
... @classmethod
|
... @classmethod
|
||||||
... def today(cls):
|
... def today(cls):
|
||||||
... print('today is %s' % cls(date.today().isoweekday()).name)
|
... print('today is %s' % cls(date.today().isoweekday()).name)
|
||||||
|
...
|
||||||
>>> dir(Weekday.SATURDAY)
|
>>> dir(Weekday.SATURDAY)
|
||||||
['__class__', '__doc__', '__eq__', '__hash__', '__module__', 'name', 'today', 'value']
|
['__class__', '__doc__', '__eq__', '__hash__', '__module__', 'name', 'today', 'value']
|
||||||
|
|
||||||
|
@ -312,6 +313,7 @@ Data Types
|
||||||
... return (count + 1) * 3
|
... return (count + 1) * 3
|
||||||
... FIRST = auto()
|
... FIRST = auto()
|
||||||
... SECOND = auto()
|
... SECOND = auto()
|
||||||
|
...
|
||||||
>>> PowersOfThree.SECOND.value
|
>>> PowersOfThree.SECOND.value
|
||||||
6
|
6
|
||||||
|
|
||||||
|
@ -336,6 +338,7 @@ Data Types
|
||||||
... if member.value == value:
|
... if member.value == value:
|
||||||
... return member
|
... return member
|
||||||
... return None
|
... return None
|
||||||
|
...
|
||||||
>>> Build.DEBUG.value
|
>>> Build.DEBUG.value
|
||||||
'debug'
|
'debug'
|
||||||
>>> Build('deBUG')
|
>>> Build('deBUG')
|
||||||
|
@ -353,6 +356,7 @@ Data Types
|
||||||
... def __repr__(self):
|
... def __repr__(self):
|
||||||
... cls_name = self.__class__.__name__
|
... cls_name = self.__class__.__name__
|
||||||
... return f'{cls_name}.{self.name}'
|
... return f'{cls_name}.{self.name}'
|
||||||
|
...
|
||||||
>>> OtherStyle.ALTERNATE, str(OtherStyle.ALTERNATE), f"{OtherStyle.ALTERNATE}"
|
>>> OtherStyle.ALTERNATE, str(OtherStyle.ALTERNATE), f"{OtherStyle.ALTERNATE}"
|
||||||
(OtherStyle.ALTERNATE, 'OtherStyle.ALTERNATE', 'OtherStyle.ALTERNATE')
|
(OtherStyle.ALTERNATE, 'OtherStyle.ALTERNATE', 'OtherStyle.ALTERNATE')
|
||||||
|
|
||||||
|
@ -367,6 +371,7 @@ Data Types
|
||||||
... SOMETHING_ELSE = auto()
|
... SOMETHING_ELSE = auto()
|
||||||
... def __str__(self):
|
... def __str__(self):
|
||||||
... return f'{self.name}'
|
... return f'{self.name}'
|
||||||
|
...
|
||||||
>>> OtherStyle.ALTERNATE, str(OtherStyle.ALTERNATE), f"{OtherStyle.ALTERNATE}"
|
>>> OtherStyle.ALTERNATE, str(OtherStyle.ALTERNATE), f"{OtherStyle.ALTERNATE}"
|
||||||
(<OtherStyle.ALTERNATE: 1>, 'ALTERNATE', 'ALTERNATE')
|
(<OtherStyle.ALTERNATE: 1>, 'ALTERNATE', 'ALTERNATE')
|
||||||
|
|
||||||
|
@ -381,6 +386,7 @@ Data Types
|
||||||
... SOMETHING_ELSE = auto()
|
... SOMETHING_ELSE = auto()
|
||||||
... def __format__(self, spec):
|
... def __format__(self, spec):
|
||||||
... return f'{self.name}'
|
... return f'{self.name}'
|
||||||
|
...
|
||||||
>>> OtherStyle.ALTERNATE, str(OtherStyle.ALTERNATE), f"{OtherStyle.ALTERNATE}"
|
>>> OtherStyle.ALTERNATE, str(OtherStyle.ALTERNATE), f"{OtherStyle.ALTERNATE}"
|
||||||
(<OtherStyle.ALTERNATE: 1>, 'OtherStyle.ALTERNATE', 'ALTERNATE')
|
(<OtherStyle.ALTERNATE: 1>, 'OtherStyle.ALTERNATE', 'ALTERNATE')
|
||||||
|
|
||||||
|
@ -403,6 +409,7 @@ Data Types
|
||||||
... ONE = 1
|
... ONE = 1
|
||||||
... TWO = 2
|
... TWO = 2
|
||||||
... THREE = 3
|
... THREE = 3
|
||||||
|
...
|
||||||
>>> Numbers.THREE
|
>>> Numbers.THREE
|
||||||
<Numbers.THREE: 3>
|
<Numbers.THREE: 3>
|
||||||
>>> Numbers.ONE + Numbers.TWO
|
>>> Numbers.ONE + Numbers.TWO
|
||||||
|
@ -463,6 +470,7 @@ Data Types
|
||||||
... RED = auto()
|
... RED = auto()
|
||||||
... GREEN = auto()
|
... GREEN = auto()
|
||||||
... BLUE = auto()
|
... BLUE = auto()
|
||||||
|
...
|
||||||
>>> purple = Color.RED | Color.BLUE
|
>>> purple = Color.RED | Color.BLUE
|
||||||
>>> white = Color.RED | Color.GREEN | Color.BLUE
|
>>> white = Color.RED | Color.GREEN | Color.BLUE
|
||||||
>>> Color.GREEN in purple
|
>>> Color.GREEN in purple
|
||||||
|
@ -570,6 +578,7 @@ Data Types
|
||||||
... RED = auto()
|
... RED = auto()
|
||||||
... GREEN = auto()
|
... GREEN = auto()
|
||||||
... BLUE = auto()
|
... BLUE = auto()
|
||||||
|
...
|
||||||
>>> Color.RED & 2
|
>>> Color.RED & 2
|
||||||
<Color: 0>
|
<Color: 0>
|
||||||
>>> Color.RED | 2
|
>>> Color.RED | 2
|
||||||
|
@ -695,6 +704,7 @@ Data Types
|
||||||
... RED = auto()
|
... RED = auto()
|
||||||
... GREEN = auto()
|
... GREEN = auto()
|
||||||
... BLUE = auto()
|
... BLUE = auto()
|
||||||
|
...
|
||||||
>>> StrictFlag(2**2 + 2**4)
|
>>> StrictFlag(2**2 + 2**4)
|
||||||
Traceback (most recent call last):
|
Traceback (most recent call last):
|
||||||
...
|
...
|
||||||
|
@ -712,6 +722,7 @@ Data Types
|
||||||
... RED = auto()
|
... RED = auto()
|
||||||
... GREEN = auto()
|
... GREEN = auto()
|
||||||
... BLUE = auto()
|
... BLUE = auto()
|
||||||
|
...
|
||||||
>>> ConformFlag(2**2 + 2**4)
|
>>> ConformFlag(2**2 + 2**4)
|
||||||
<ConformFlag.BLUE: 4>
|
<ConformFlag.BLUE: 4>
|
||||||
|
|
||||||
|
@ -725,6 +736,7 @@ Data Types
|
||||||
... RED = auto()
|
... RED = auto()
|
||||||
... GREEN = auto()
|
... GREEN = auto()
|
||||||
... BLUE = auto()
|
... BLUE = auto()
|
||||||
|
...
|
||||||
>>> EjectFlag(2**2 + 2**4)
|
>>> EjectFlag(2**2 + 2**4)
|
||||||
20
|
20
|
||||||
|
|
||||||
|
@ -738,6 +750,7 @@ Data Types
|
||||||
... RED = auto()
|
... RED = auto()
|
||||||
... GREEN = auto()
|
... GREEN = auto()
|
||||||
... BLUE = auto()
|
... BLUE = auto()
|
||||||
|
...
|
||||||
>>> KeepFlag(2**2 + 2**4)
|
>>> KeepFlag(2**2 + 2**4)
|
||||||
<KeepFlag.BLUE|16: 20>
|
<KeepFlag.BLUE|16: 20>
|
||||||
|
|
||||||
|
|
|
@ -462,6 +462,7 @@ are always available. They are listed here in alphabetical order.
|
||||||
>>> class Shape:
|
>>> class Shape:
|
||||||
... def __dir__(self):
|
... def __dir__(self):
|
||||||
... return ['area', 'perimeter', 'location']
|
... return ['area', 'perimeter', 'location']
|
||||||
|
...
|
||||||
>>> s = Shape()
|
>>> s = Shape()
|
||||||
>>> dir(s)
|
>>> dir(s)
|
||||||
['area', 'location', 'perimeter']
|
['area', 'location', 'perimeter']
|
||||||
|
|
|
@ -497,6 +497,7 @@ update the hash:
|
||||||
>>> h = blake2b()
|
>>> h = blake2b()
|
||||||
>>> for item in items:
|
>>> for item in items:
|
||||||
... h.update(item)
|
... h.update(item)
|
||||||
|
...
|
||||||
>>> h.hexdigest()
|
>>> h.hexdigest()
|
||||||
'6ff843ba685842aa82031d3f53c48b66326df7639a63d128974c5c14f31a0f33343a8c65551134ed1ae0f2b0dd2bb495dc81039e3eeb0aa1bb0388bbeac29183'
|
'6ff843ba685842aa82031d3f53c48b66326df7639a63d128974c5c14f31a0f33343a8c65551134ed1ae0f2b0dd2bb495dc81039e3eeb0aa1bb0388bbeac29183'
|
||||||
|
|
||||||
|
|
|
@ -715,6 +715,7 @@ function.
|
||||||
|
|
||||||
>>> def test(a, b):
|
>>> def test(a, b):
|
||||||
... pass
|
... pass
|
||||||
|
...
|
||||||
>>> sig = signature(test)
|
>>> sig = signature(test)
|
||||||
>>> new_sig = sig.replace(return_annotation="new return anno")
|
>>> new_sig = sig.replace(return_annotation="new return anno")
|
||||||
>>> str(new_sig)
|
>>> str(new_sig)
|
||||||
|
@ -1054,6 +1055,7 @@ Classes and functions
|
||||||
>>> from inspect import getcallargs
|
>>> from inspect import getcallargs
|
||||||
>>> def f(a, b=1, *pos, **named):
|
>>> def f(a, b=1, *pos, **named):
|
||||||
... pass
|
... pass
|
||||||
|
...
|
||||||
>>> getcallargs(f, 1, 2, 3) == {'a': 1, 'named': {}, 'b': 2, 'pos': (3,)}
|
>>> getcallargs(f, 1, 2, 3) == {'a': 1, 'named': {}, 'b': 2, 'pos': (3,)}
|
||||||
True
|
True
|
||||||
>>> getcallargs(f, a=2, x=4) == {'a': 2, 'named': {'x': 4}, 'b': 1, 'pos': ()}
|
>>> getcallargs(f, a=2, x=4) == {'a': 2, 'named': {'x': 4}, 'b': 1, 'pos': ()}
|
||||||
|
|
|
@ -973,6 +973,7 @@ Functions
|
||||||
>>> def dashrepl(matchobj):
|
>>> def dashrepl(matchobj):
|
||||||
... if matchobj.group(0) == '-': return ' '
|
... if matchobj.group(0) == '-': return ' '
|
||||||
... else: return '-'
|
... else: return '-'
|
||||||
|
...
|
||||||
>>> re.sub('-{1,2}', dashrepl, 'pro----gram-files')
|
>>> re.sub('-{1,2}', dashrepl, 'pro----gram-files')
|
||||||
'pro--gram files'
|
'pro--gram files'
|
||||||
>>> re.sub(r'\sAND\s', ' & ', 'Baked Beans And Spam', flags=re.IGNORECASE)
|
>>> re.sub(r'\sAND\s', ' & ', 'Baked Beans And Spam', flags=re.IGNORECASE)
|
||||||
|
@ -1672,6 +1673,7 @@ in each word of a sentence except for the first and last characters::
|
||||||
... inner_word = list(m.group(2))
|
... inner_word = list(m.group(2))
|
||||||
... random.shuffle(inner_word)
|
... random.shuffle(inner_word)
|
||||||
... return m.group(1) + "".join(inner_word) + m.group(3)
|
... return m.group(1) + "".join(inner_word) + m.group(3)
|
||||||
|
...
|
||||||
>>> text = "Professor Abdolmalek, please report your absences promptly."
|
>>> text = "Professor Abdolmalek, please report your absences promptly."
|
||||||
>>> re.sub(r"(\w)(\w+)(\w)", repl, text)
|
>>> re.sub(r"(\w)(\w+)(\w)", repl, text)
|
||||||
'Poefsrosr Aealmlobdk, pslaee reorpt your abnseces plmrptoy.'
|
'Poefsrosr Aealmlobdk, pslaee reorpt your abnseces plmrptoy.'
|
||||||
|
|
|
@ -397,6 +397,7 @@ Module functions
|
||||||
>>> con = sqlite3.connect(":memory:")
|
>>> con = sqlite3.connect(":memory:")
|
||||||
>>> def evil_trace(stmt):
|
>>> def evil_trace(stmt):
|
||||||
... 5/0
|
... 5/0
|
||||||
|
...
|
||||||
>>> con.set_trace_callback(evil_trace)
|
>>> con.set_trace_callback(evil_trace)
|
||||||
>>> def debug(unraisable):
|
>>> def debug(unraisable):
|
||||||
... print(f"{unraisable.exc_value!r} in callback {unraisable.object.__name__}")
|
... print(f"{unraisable.exc_value!r} in callback {unraisable.object.__name__}")
|
||||||
|
|
|
@ -996,6 +996,7 @@ probability that the Python room will stay within its capacity limits?
|
||||||
>>> seed(8675309)
|
>>> seed(8675309)
|
||||||
>>> def trial():
|
>>> def trial():
|
||||||
... return choices(('Python', 'Ruby'), (p, q), k=n).count('Python')
|
... return choices(('Python', 'Ruby'), (p, q), k=n).count('Python')
|
||||||
|
...
|
||||||
>>> mean(trial() <= k for i in range(10_000))
|
>>> mean(trial() <= k for i in range(10_000))
|
||||||
0.8398
|
0.8398
|
||||||
|
|
||||||
|
|
|
@ -4459,6 +4459,7 @@ can be used interchangeably to index the same dictionary entry.
|
||||||
>>> class Counter(dict):
|
>>> class Counter(dict):
|
||||||
... def __missing__(self, key):
|
... def __missing__(self, key):
|
||||||
... return 0
|
... return 0
|
||||||
|
...
|
||||||
>>> c = Counter()
|
>>> c = Counter()
|
||||||
>>> c['red']
|
>>> c['red']
|
||||||
0
|
0
|
||||||
|
@ -4716,6 +4717,7 @@ An example of dictionary view usage::
|
||||||
>>> n = 0
|
>>> n = 0
|
||||||
>>> for val in values:
|
>>> for val in values:
|
||||||
... n += val
|
... n += val
|
||||||
|
...
|
||||||
>>> print(n)
|
>>> print(n)
|
||||||
504
|
504
|
||||||
|
|
||||||
|
|
|
@ -1604,6 +1604,7 @@ decorator:
|
||||||
>>> @patch.dict(foo, {'newkey': 'newvalue'})
|
>>> @patch.dict(foo, {'newkey': 'newvalue'})
|
||||||
... def test():
|
... def test():
|
||||||
... assert foo == {'newkey': 'newvalue'}
|
... assert foo == {'newkey': 'newvalue'}
|
||||||
|
...
|
||||||
>>> test()
|
>>> test()
|
||||||
>>> assert foo == {}
|
>>> assert foo == {}
|
||||||
|
|
||||||
|
|
|
@ -1212,6 +1212,7 @@ Example of changing the attribute "target" of every link in first paragraph::
|
||||||
[<Element 'a' at 0xb77ec2ac>, <Element 'a' at 0xb77ec1cc>]
|
[<Element 'a' at 0xb77ec2ac>, <Element 'a' at 0xb77ec1cc>]
|
||||||
>>> for i in links: # Iterates through all found links
|
>>> for i in links: # Iterates through all found links
|
||||||
... i.attrib["target"] = "blank"
|
... i.attrib["target"] = "blank"
|
||||||
|
...
|
||||||
>>> tree.write("output.xhtml")
|
>>> tree.write("output.xhtml")
|
||||||
|
|
||||||
.. _elementtree-qname-objects:
|
.. _elementtree-qname-objects:
|
||||||
|
|
|
@ -672,6 +672,7 @@ The :class:`PyZipFile` constructor takes the same parameters as the
|
||||||
>>> def notests(s):
|
>>> def notests(s):
|
||||||
... fn = os.path.basename(s)
|
... fn = os.path.basename(s)
|
||||||
... return (not (fn == 'test' or fn.startswith('test_')))
|
... return (not (fn == 'test' or fn.startswith('test_')))
|
||||||
|
...
|
||||||
>>> zf.writepy('myprog', filterfunc=notests)
|
>>> zf.writepy('myprog', filterfunc=notests)
|
||||||
|
|
||||||
The :meth:`writepy` method makes archives with file names like
|
The :meth:`writepy` method makes archives with file names like
|
||||||
|
|
|
@ -1331,6 +1331,7 @@ changes, or look through the Subversion logs for all the details.
|
||||||
>>> from inspect import getcallargs
|
>>> from inspect import getcallargs
|
||||||
>>> def f(a, b=1, *pos, **named):
|
>>> def f(a, b=1, *pos, **named):
|
||||||
... pass
|
... pass
|
||||||
|
...
|
||||||
>>> getcallargs(f, 1, 2, 3)
|
>>> getcallargs(f, 1, 2, 3)
|
||||||
{'a': 1, 'b': 2, 'pos': (3,), 'named': {}}
|
{'a': 1, 'b': 2, 'pos': (3,), 'named': {}}
|
||||||
>>> getcallargs(f, a=2, x=4)
|
>>> getcallargs(f, a=2, x=4)
|
||||||
|
|
|
@ -468,6 +468,7 @@ Some smaller changes made to the core Python language are:
|
||||||
>>> class LowerCasedDict(dict):
|
>>> class LowerCasedDict(dict):
|
||||||
... def __getitem__(self, key):
|
... def __getitem__(self, key):
|
||||||
... return dict.__getitem__(self, key.lower())
|
... return dict.__getitem__(self, key.lower())
|
||||||
|
...
|
||||||
>>> lcd = LowerCasedDict(part='widgets', quantity=10)
|
>>> lcd = LowerCasedDict(part='widgets', quantity=10)
|
||||||
>>> 'There are {QUANTITY} {Part} in stock'.format_map(lcd)
|
>>> 'There are {QUANTITY} {Part} in stock'.format_map(lcd)
|
||||||
'There are 10 widgets in stock'
|
'There are 10 widgets in stock'
|
||||||
|
@ -475,6 +476,7 @@ Some smaller changes made to the core Python language are:
|
||||||
>>> class PlaceholderDict(dict):
|
>>> class PlaceholderDict(dict):
|
||||||
... def __missing__(self, key):
|
... def __missing__(self, key):
|
||||||
... return '<{}>'.format(key)
|
... return '<{}>'.format(key)
|
||||||
|
...
|
||||||
>>> 'Hello {name}, welcome to {location}'.format_map(PlaceholderDict())
|
>>> 'Hello {name}, welcome to {location}'.format_map(PlaceholderDict())
|
||||||
'Hello <name>, welcome to <location>'
|
'Hello <name>, welcome to <location>'
|
||||||
|
|
||||||
|
@ -1886,6 +1888,7 @@ inspect
|
||||||
>>> from inspect import getgeneratorstate
|
>>> from inspect import getgeneratorstate
|
||||||
>>> def gen():
|
>>> def gen():
|
||||||
... yield 'demo'
|
... yield 'demo'
|
||||||
|
...
|
||||||
>>> g = gen()
|
>>> g = gen()
|
||||||
>>> getgeneratorstate(g)
|
>>> getgeneratorstate(g)
|
||||||
'GEN_CREATED'
|
'GEN_CREATED'
|
||||||
|
|
|
@ -560,6 +560,7 @@ Example with (non-bound) methods::
|
||||||
>>> class C:
|
>>> class C:
|
||||||
... def meth(self):
|
... def meth(self):
|
||||||
... pass
|
... pass
|
||||||
|
...
|
||||||
>>> C.meth.__name__
|
>>> C.meth.__name__
|
||||||
'meth'
|
'meth'
|
||||||
>>> C.meth.__qualname__
|
>>> C.meth.__qualname__
|
||||||
|
|
Loading…
Reference in New Issue