From 5c89cdae0a4431959b7fd26ec915c1927d2c759a Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Sun, 20 Feb 2011 10:37:07 +0000 Subject: Bump trunk to 3.3 alpha 0. --- Doc/tutorial/interpreter.rst | 14 +++++++------- Doc/tutorial/stdlib.rst | 2 +- Doc/tutorial/stdlib2.rst | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) (limited to 'Doc/tutorial') diff --git a/Doc/tutorial/interpreter.rst b/Doc/tutorial/interpreter.rst index 8d743de34f..eeddf766dd 100644 --- a/Doc/tutorial/interpreter.rst +++ b/Doc/tutorial/interpreter.rst @@ -10,11 +10,11 @@ Using the Python Interpreter Invoking the Interpreter ======================== -The Python interpreter is usually installed as :file:`/usr/local/bin/python3.2` +The Python interpreter is usually installed as :file:`/usr/local/bin/python3.3` on those machines where it is available; putting :file:`/usr/local/bin` in your Unix shell's search path makes it possible to start it by typing the command :: - python3.2 + python3.3 to the shell. [#]_ Since the choice of the directory where the interpreter lives is an installation option, other places are possible; check with your local @@ -22,11 +22,11 @@ Python guru or system administrator. (E.g., :file:`/usr/local/python` is a popular alternative location.) On Windows machines, the Python installation is usually placed in -:file:`C:\\Python32`, though you can change this when you're running the +:file:`C:\\Python33`, though you can change this when you're running the installer. To add this directory to your path, you can type the following command into the command prompt in a DOS box:: - set path=%path%;C:\python32 + set path=%path%;C:\python33 Typing an end-of-file character (:kbd:`Control-D` on Unix, :kbd:`Control-Z` on Windows) at the primary prompt causes the interpreter to exit with a zero exit @@ -94,8 +94,8 @@ with the *secondary prompt*, by default three dots (``...``). The interpreter prints a welcome message stating its version number and a copyright notice before printing the first prompt:: - $ python3.2 - Python 3.2 (py3k, Sep 12 2007, 12:21:02) + $ python3.3 + Python 3.3 (py3k, Sep 12 2007, 12:21:02) [GCC 3.4.6 20060404 (Red Hat 3.4.6-8)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> @@ -148,7 +148,7 @@ Executable Python Scripts On BSD'ish Unix systems, Python scripts can be made directly executable, like shell scripts, by putting the line :: - #! /usr/bin/env python3.2 + #! /usr/bin/env python3.3 (assuming that the interpreter is on the user's :envvar:`PATH`) at the beginning of the script and giving the file an executable mode. The ``#!`` must be the diff --git a/Doc/tutorial/stdlib.rst b/Doc/tutorial/stdlib.rst index 97297434ed..500ca7f623 100644 --- a/Doc/tutorial/stdlib.rst +++ b/Doc/tutorial/stdlib.rst @@ -15,7 +15,7 @@ operating system:: >>> import os >>> os.getcwd() # Return the current working directory - 'C:\\Python31' + 'C:\\Python33' >>> os.chdir('/server/accesslogs') # Change current working directory >>> os.system('mkdir today') # Run the command mkdir in the system shell 0 diff --git a/Doc/tutorial/stdlib2.rst b/Doc/tutorial/stdlib2.rst index fe7f027b53..603f143aa0 100644 --- a/Doc/tutorial/stdlib2.rst +++ b/Doc/tutorial/stdlib2.rst @@ -271,7 +271,7 @@ applications include caching objects that are expensive to create:: Traceback (most recent call last): File "", line 1, in d['primary'] # entry was automatically removed - File "C:/python31/lib/weakref.py", line 46, in __getitem__ + File "C:/python33/lib/weakref.py", line 46, in __getitem__ o = self.data[key]() KeyError: 'primary' -- cgit v1.2.1 From 957f62642ddb8f666541b0ed03cb9d4c5c5e5bb5 Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Thu, 24 Feb 2011 00:08:13 +0000 Subject: Issue #11304: Input/output tutorial - PI is rounded not truncated. --- Doc/tutorial/inputoutput.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Doc/tutorial') diff --git a/Doc/tutorial/inputoutput.rst b/Doc/tutorial/inputoutput.rst index 04665f8801..d94bfe07dd 100644 --- a/Doc/tutorial/inputoutput.rst +++ b/Doc/tutorial/inputoutput.rst @@ -163,7 +163,7 @@ Positional and keyword arguments can be arbitrarily combined:: An optional ``':'`` and format specifier can follow the field name. This allows greater control over how the value is formatted. The following example -truncates Pi to three places after the decimal. +rounds Pi to three places after the decimal. >>> import math >>> print('The value of PI is approximately {0:.3f}.'.format(math.pi)) -- cgit v1.2.1 From 4e673d6ab4524ce09b5ae30881ab5e03305201ef Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Mon, 7 Mar 2011 08:31:52 +0100 Subject: Name c -> cls in example. --- Doc/tutorial/classes.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Doc/tutorial') diff --git a/Doc/tutorial/classes.rst b/Doc/tutorial/classes.rst index 576ef3a49c..a0f2431e5e 100644 --- a/Doc/tutorial/classes.rst +++ b/Doc/tutorial/classes.rst @@ -673,9 +673,9 @@ example, the following code will print B, C, D in that order:: class D(C): pass - for c in [B, C, D]: + for cls in [B, C, D]: try: - raise c() + raise cls() except D: print("D") except C: -- cgit v1.2.1 From 29efd36201031735946f19f392bb94d1e47233c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Araujo?= Date: Fri, 11 Mar 2011 17:42:48 +0100 Subject: Use with statement where it improves the documentation (closes #10461) --- Doc/tutorial/stdlib2.rst | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'Doc/tutorial') diff --git a/Doc/tutorial/stdlib2.rst b/Doc/tutorial/stdlib2.rst index 603f143aa0..85c88dc23f 100644 --- a/Doc/tutorial/stdlib2.rst +++ b/Doc/tutorial/stdlib2.rst @@ -141,7 +141,9 @@ standard size and in little-endian byte order:: import struct - data = open('myfile.zip', 'rb').read() + with open('myfile.zip', 'rb') as f: + data = f.read() + start = 0 for i in range(3): # show the first 3 file headers start += 14 -- cgit v1.2.1 From 4f219b295bc994da38b2940392c14c3c547a5933 Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Sun, 1 May 2011 22:34:31 +0200 Subject: Split combined code/doctest code blocks in two blocks, to enable proper highlighting. --- Doc/tutorial/classes.rst | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'Doc/tutorial') diff --git a/Doc/tutorial/classes.rst b/Doc/tutorial/classes.rst index a0f2431e5e..04abcf3f22 100644 --- a/Doc/tutorial/classes.rst +++ b/Doc/tutorial/classes.rst @@ -754,6 +754,8 @@ returns an object with a :meth:`__next__` method. If the class defines self.index = self.index - 1 return self.data[self.index] +:: + >>> rev = Reverse('spam') >>> iter(rev) <__main__.Reverse object at 0x00A1DB50> @@ -782,6 +784,8 @@ easy to create:: for index in range(len(data)-1, -1, -1): yield data[index] +:: + >>> for char in reverse('golf'): ... print(char) ... -- cgit v1.2.1 From 86fcfb5b9cb0fa53c8a120fd65e962d864e44fb9 Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Sat, 8 Oct 2011 18:32:40 +0200 Subject: Closes #12192: Document that mutating list methods do not return the instance (original patch by Mike Hoy). --- Doc/tutorial/datastructures.rst | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) (limited to 'Doc/tutorial') diff --git a/Doc/tutorial/datastructures.rst b/Doc/tutorial/datastructures.rst index defb47c72c..44c09c37c0 100644 --- a/Doc/tutorial/datastructures.rst +++ b/Doc/tutorial/datastructures.rst @@ -19,13 +19,13 @@ objects: .. method:: list.append(x) :noindex: - Add an item to the end of the list; equivalent to ``a[len(a):] = [x]``. + Add an item to the end of the list. Equivalent to ``a[len(a):] = [x]``. .. method:: list.extend(L) :noindex: - Extend the list by appending all the items in the given list; equivalent to + Extend the list by appending all the items in the given list. Equivalent to ``a[len(a):] = L``. @@ -40,8 +40,8 @@ objects: .. method:: list.remove(x) :noindex: - Remove the first item from the list whose value is *x*. It is an error if there - is no such item. + Remove the first item from the list whose value is *x*. It is an error if + there is no such item. .. method:: list.pop([i]) @@ -70,13 +70,14 @@ objects: .. method:: list.sort() :noindex: - Sort the items of the list, in place. + Sort the items of the list in place. .. method:: list.reverse() :noindex: - Reverse the elements of the list, in place. + Reverse the elements of the list in place. + An example that uses most of the list methods:: @@ -99,6 +100,10 @@ An example that uses most of the list methods:: >>> a [-1, 1, 66.25, 333, 333, 1234.5] +You might have noticed that methods like ``insert``, ``remove`` or ``sort`` that +modify the list have no return value printed -- they return ``None``. [1]_ This +is a design principle for all mutable data structures in Python. + .. _tut-lists-as-stacks: @@ -438,7 +443,7 @@ using a non-existent key. Performing ``list(d.keys())`` on a dictionary returns a list of all the keys used in the dictionary, in arbitrary order (if you want it sorted, just use -``sorted(d.keys())`` instead). [1]_ To check whether a single key is in the +``sorted(d.keys())`` instead). [2]_ To check whether a single key is in the dictionary, use the :keyword:`in` keyword. Here is a small example using a dictionary:: @@ -622,6 +627,9 @@ interpreter will raise a :exc:`TypeError` exception. .. rubric:: Footnotes -.. [1] Calling ``d.keys()`` will return a :dfn:`dictionary view` object. It +.. [1] Other languages may return the mutated object, which allows method + chaining, such as ``d->insert("a")->remove("b")->sort();``. + +.. [2] Calling ``d.keys()`` will return a :dfn:`dictionary view` object. It supports operations like membership test and iteration, but its contents are not independent of the original dictionary -- it is only a *view*. -- cgit v1.2.1