├── Pyhton-Official-Tutorial-html ├── _sources │ ├── appendix.rst.txt │ ├── appetite.rst.txt │ ├── classes.rst.txt │ ├── controlflow.rst.txt │ ├── datastructures.rst.txt │ ├── errors.rst.txt │ ├── floatingpoint.rst.txt │ ├── index.rst.txt │ ├── inputoutput.rst.txt │ ├── interactive.rst.txt │ ├── interpreter.rst.txt │ ├── introduction.rst.txt │ ├── modules.rst.txt │ ├── stdlib.rst.txt │ ├── stdlib2.rst.txt │ ├── venv.rst.txt │ └── whatnow.rst.txt ├── _static │ ├── ajax-loader.gif │ ├── alabaster.css │ ├── basic.css │ ├── comment-bright.png │ ├── comment-close.png │ ├── comment.png │ ├── custom.css │ ├── doctools.js │ ├── documentation_options.js │ ├── down-pressed.png │ ├── down.png │ ├── file.png │ ├── jquery-3.2.1.js │ ├── jquery.js │ ├── minus.png │ ├── plus.png │ ├── pygments.css │ ├── searchtools.js │ ├── underscore-1.3.1.js │ ├── underscore.js │ ├── up-pressed.png │ ├── up.png │ └── websupport.js ├── appendix.html ├── appetite.html ├── classes.html ├── controlflow.html ├── datastructures.html ├── errors.html ├── floatingpoint.html ├── genindex.html ├── index.html ├── inputoutput.html ├── interactive.html ├── interpreter.html ├── introduction.html ├── modules.html ├── objects.inv ├── search.html ├── searchindex.js ├── stdlib.html ├── stdlib2.html ├── venv.html └── whatnow.html ├── Pyhton-Official-Tutorial-ipynb ├── appendix.rst.ipynb ├── appetite.rst.ipynb ├── classes.rst.ipynb ├── controlflow.rst.ipynb ├── datastructures.rst.ipynb ├── errors.rst.ipynb ├── floatingpoint.rst.ipynb ├── index.rst.ipynb ├── inputoutput.rst.ipynb ├── interactive.rst.ipynb ├── interpreter.rst.ipynb ├── introduction.rst.ipynb ├── modules.rst.ipynb ├── stdlib.rst.ipynb ├── stdlib2.rst.ipynb ├── venv.rst.ipynb └── whatnow.rst.ipynb ├── PythonOfficialTutorial.epub └── README.md /Pyhton-Official-Tutorial-html/_sources/appendix.rst.txt: -------------------------------------------------------------------------------- 1 | .. _tut-appendix: 2 | 3 | ******** 4 | Appendix 5 | ******** 6 | 7 | 8 | .. _tut-interac: 9 | 10 | Interactive Mode 11 | ================ 12 | 13 | .. _tut-error: 14 | 15 | Error Handling 16 | -------------- 17 | 18 | When an error occurs, the interpreter prints an error message and a stack trace. 19 | In interactive mode, it then returns to the primary prompt; when input came from 20 | a file, it exits with a nonzero exit status after printing the stack trace. 21 | (Exceptions handled by an :keyword:`except` clause in a :keyword:`try` statement 22 | are not errors in this context.) Some errors are unconditionally fatal and 23 | cause an exit with a nonzero exit; this applies to internal inconsistencies and 24 | some cases of running out of memory. All error messages are written to the 25 | standard error stream; normal output from executed commands is written to 26 | standard output. 27 | 28 | Typing the interrupt character (usually :kbd:`Control-C` or :kbd:`Delete`) to the primary or 29 | secondary prompt cancels the input and returns to the primary prompt. [#]_ 30 | Typing an interrupt while a command is executing raises the 31 | :exc:`KeyboardInterrupt` exception, which may be handled by a :keyword:`try` 32 | statement. 33 | 34 | 35 | .. _tut-scripts: 36 | 37 | Executable Python Scripts 38 | ------------------------- 39 | 40 | On BSD'ish Unix systems, Python scripts can be made directly executable, like 41 | shell scripts, by putting the line :: 42 | 43 | #!/usr/bin/env python3.5 44 | 45 | (assuming that the interpreter is on the user's :envvar:`PATH`) at the beginning 46 | of the script and giving the file an executable mode. The ``#!`` must be the 47 | first two characters of the file. On some platforms, this first line must end 48 | with a Unix-style line ending (``'\n'``), not a Windows (``'\r\n'``) line 49 | ending. Note that the hash, or pound, character, ``'#'``, is used to start a 50 | comment in Python. 51 | 52 | The script can be given an executable mode, or permission, using the 53 | :program:`chmod` command. 54 | 55 | .. code-block:: shell-session 56 | 57 | $ chmod +x myscript.py 58 | 59 | On Windows systems, there is no notion of an "executable mode". The Python 60 | installer automatically associates ``.py`` files with ``python.exe`` so that 61 | a double-click on a Python file will run it as a script. The extension can 62 | also be ``.pyw``, in that case, the console window that normally appears is 63 | suppressed. 64 | 65 | 66 | .. _tut-startup: 67 | 68 | The Interactive Startup File 69 | ---------------------------- 70 | 71 | When you use Python interactively, it is frequently handy to have some standard 72 | commands executed every time the interpreter is started. You can do this by 73 | setting an environment variable named :envvar:`PYTHONSTARTUP` to the name of a 74 | file containing your start-up commands. This is similar to the :file:`.profile` 75 | feature of the Unix shells. 76 | 77 | This file is only read in interactive sessions, not when Python reads commands 78 | from a script, and not when :file:`/dev/tty` is given as the explicit source of 79 | commands (which otherwise behaves like an interactive session). It is executed 80 | in the same namespace where interactive commands are executed, so that objects 81 | that it defines or imports can be used without qualification in the interactive 82 | session. You can also change the prompts ``sys.ps1`` and ``sys.ps2`` in this 83 | file. 84 | 85 | If you want to read an additional start-up file from the current directory, you 86 | can program this in the global start-up file using code like ``if 87 | os.path.isfile('.pythonrc.py'): exec(open('.pythonrc.py').read())``. 88 | If you want to use the startup file in a script, you must do this explicitly 89 | in the script:: 90 | 91 | import os 92 | filename = os.environ.get('PYTHONSTARTUP') 93 | if filename and os.path.isfile(filename): 94 | with open(filename) as fobj: 95 | startup_file = fobj.read() 96 | exec(startup_file) 97 | 98 | 99 | .. _tut-customize: 100 | 101 | The Customization Modules 102 | ------------------------- 103 | 104 | Python provides two hooks to let you customize it: :mod:`sitecustomize` and 105 | :mod:`usercustomize`. To see how it works, you need first to find the location 106 | of your user site-packages directory. Start Python and run this code:: 107 | 108 | >>> import site 109 | >>> site.getusersitepackages() 110 | '/home/user/.local/lib/python3.5/site-packages' 111 | 112 | Now you can create a file named :file:`usercustomize.py` in that directory and 113 | put anything you want in it. It will affect every invocation of Python, unless 114 | it is started with the :option:`-s` option to disable the automatic import. 115 | 116 | :mod:`sitecustomize` works in the same way, but is typically created by an 117 | administrator of the computer in the global site-packages directory, and is 118 | imported before :mod:`usercustomize`. See the documentation of the :mod:`site` 119 | module for more details. 120 | 121 | 122 | .. rubric:: Footnotes 123 | 124 | .. [#] A problem with the GNU Readline package may prevent this. 125 | -------------------------------------------------------------------------------- /Pyhton-Official-Tutorial-html/_sources/appetite.rst.txt: -------------------------------------------------------------------------------- 1 | .. _tut-intro: 2 | 3 | ********************** 4 | Whetting Your Appetite 5 | ********************** 6 | 7 | If you do much work on computers, eventually you find that there's some task 8 | you'd like to automate. For example, you may wish to perform a 9 | search-and-replace over a large number of text files, or rename and rearrange a 10 | bunch of photo files in a complicated way. Perhaps you'd like to write a small 11 | custom database, or a specialized GUI application, or a simple game. 12 | 13 | If you're a professional software developer, you may have to work with several 14 | C/C++/Java libraries but find the usual write/compile/test/re-compile cycle is 15 | too slow. Perhaps you're writing a test suite for such a library and find 16 | writing the testing code a tedious task. Or maybe you've written a program that 17 | could use an extension language, and you don't want to design and implement a 18 | whole new language for your application. 19 | 20 | Python is just the language for you. 21 | 22 | You could write a Unix shell script or Windows batch files for some of these 23 | tasks, but shell scripts are best at moving around files and changing text data, 24 | not well-suited for GUI applications or games. You could write a C/C++/Java 25 | program, but it can take a lot of development time to get even a first-draft 26 | program. Python is simpler to use, available on Windows, Mac OS X, and Unix 27 | operating systems, and will help you get the job done more quickly. 28 | 29 | Python is simple to use, but it is a real programming language, offering much 30 | more structure and support for large programs than shell scripts or batch files 31 | can offer. On the other hand, Python also offers much more error checking than 32 | C, and, being a *very-high-level language*, it has high-level data types built 33 | in, such as flexible arrays and dictionaries. Because of its more general data 34 | types Python is applicable to a much larger problem domain than Awk or even 35 | Perl, yet many things are at least as easy in Python as in those languages. 36 | 37 | Python allows you to split your program into modules that can be reused in other 38 | Python programs. It comes with a large collection of standard modules that you 39 | can use as the basis of your programs --- or as examples to start learning to 40 | program in Python. Some of these modules provide things like file I/O, system 41 | calls, sockets, and even interfaces to graphical user interface toolkits like 42 | Tk. 43 | 44 | Python is an interpreted language, which can save you considerable time during 45 | program development because no compilation and linking is necessary. The 46 | interpreter can be used interactively, which makes it easy to experiment with 47 | features of the language, to write throw-away programs, or to test functions 48 | during bottom-up program development. It is also a handy desk calculator. 49 | 50 | Python enables programs to be written compactly and readably. Programs written 51 | in Python are typically much shorter than equivalent C, C++, or Java programs, 52 | for several reasons: 53 | 54 | * the high-level data types allow you to express complex operations in a single 55 | statement; 56 | 57 | * statement grouping is done by indentation instead of beginning and ending 58 | brackets; 59 | 60 | * no variable or argument declarations are necessary. 61 | 62 | Python is *extensible*: if you know how to program in C it is easy to add a new 63 | built-in function or module to the interpreter, either to perform critical 64 | operations at maximum speed, or to link Python programs to libraries that may 65 | only be available in binary form (such as a vendor-specific graphics library). 66 | Once you are really hooked, you can link the Python interpreter into an 67 | application written in C and use it as an extension or command language for that 68 | application. 69 | 70 | By the way, the language is named after the BBC show "Monty Python's Flying 71 | Circus" and has nothing to do with reptiles. Making references to Monty 72 | Python skits in documentation is not only allowed, it is encouraged! 73 | 74 | Now that you are all excited about Python, you'll want to examine it in some 75 | more detail. Since the best way to learn a language is to use it, the tutorial 76 | invites you to play with the Python interpreter as you read. 77 | 78 | In the next chapter, the mechanics of using the interpreter are explained. This 79 | is rather mundane information, but essential for trying out the examples shown 80 | later. 81 | 82 | The rest of the tutorial introduces various features of the Python language and 83 | system through examples, beginning with simple expressions, statements and data 84 | types, through functions and modules, and finally touching upon advanced 85 | concepts like exceptions and user-defined classes. 86 | 87 | 88 | -------------------------------------------------------------------------------- /Pyhton-Official-Tutorial-html/_sources/floatingpoint.rst.txt: -------------------------------------------------------------------------------- 1 | .. testsetup:: 2 | 3 | import math 4 | 5 | .. _tut-fp-issues: 6 | 7 | ************************************************** 8 | Floating Point Arithmetic: Issues and Limitations 9 | ************************************************** 10 | 11 | .. sectionauthor:: Tim Peters 12 | 13 | 14 | Floating-point numbers are represented in computer hardware as base 2 (binary) 15 | fractions. For example, the decimal fraction :: 16 | 17 | 0.125 18 | 19 | has value 1/10 + 2/100 + 5/1000, and in the same way the binary fraction :: 20 | 21 | 0.001 22 | 23 | has value 0/2 + 0/4 + 1/8. These two fractions have identical values, the only 24 | real difference being that the first is written in base 10 fractional notation, 25 | and the second in base 2. 26 | 27 | Unfortunately, most decimal fractions cannot be represented exactly as binary 28 | fractions. A consequence is that, in general, the decimal floating-point 29 | numbers you enter are only approximated by the binary floating-point numbers 30 | actually stored in the machine. 31 | 32 | The problem is easier to understand at first in base 10. Consider the fraction 33 | 1/3. You can approximate that as a base 10 fraction:: 34 | 35 | 0.3 36 | 37 | or, better, :: 38 | 39 | 0.33 40 | 41 | or, better, :: 42 | 43 | 0.333 44 | 45 | and so on. No matter how many digits you're willing to write down, the result 46 | will never be exactly 1/3, but will be an increasingly better approximation of 47 | 1/3. 48 | 49 | In the same way, no matter how many base 2 digits you're willing to use, the 50 | decimal value 0.1 cannot be represented exactly as a base 2 fraction. In base 51 | 2, 1/10 is the infinitely repeating fraction :: 52 | 53 | 0.0001100110011001100110011001100110011001100110011... 54 | 55 | Stop at any finite number of bits, and you get an approximation. On most 56 | machines today, floats are approximated using a binary fraction with 57 | the numerator using the first 53 bits starting with the most significant bit and 58 | with the denominator as a power of two. In the case of 1/10, the binary fraction 59 | is ``3602879701896397 / 2 ** 55`` which is close to but not exactly 60 | equal to the true value of 1/10. 61 | 62 | Many users are not aware of the approximation because of the way values are 63 | displayed. Python only prints a decimal approximation to the true decimal 64 | value of the binary approximation stored by the machine. On most machines, if 65 | Python were to print the true decimal value of the binary approximation stored 66 | for 0.1, it would have to display :: 67 | 68 | >>> 0.1 69 | 0.1000000000000000055511151231257827021181583404541015625 70 | 71 | That is more digits than most people find useful, so Python keeps the number 72 | of digits manageable by displaying a rounded value instead :: 73 | 74 | >>> 1 / 10 75 | 0.1 76 | 77 | Just remember, even though the printed result looks like the exact value 78 | of 1/10, the actual stored value is the nearest representable binary fraction. 79 | 80 | Interestingly, there are many different decimal numbers that share the same 81 | nearest approximate binary fraction. For example, the numbers ``0.1`` and 82 | ``0.10000000000000001`` and 83 | ``0.1000000000000000055511151231257827021181583404541015625`` are all 84 | approximated by ``3602879701896397 / 2 ** 55``. Since all of these decimal 85 | values share the same approximation, any one of them could be displayed 86 | while still preserving the invariant ``eval(repr(x)) == x``. 87 | 88 | Historically, the Python prompt and built-in :func:`repr` function would choose 89 | the one with 17 significant digits, ``0.10000000000000001``. Starting with 90 | Python 3.1, Python (on most systems) is now able to choose the shortest of 91 | these and simply display ``0.1``. 92 | 93 | Note that this is in the very nature of binary floating-point: this is not a bug 94 | in Python, and it is not a bug in your code either. You'll see the same kind of 95 | thing in all languages that support your hardware's floating-point arithmetic 96 | (although some languages may not *display* the difference by default, or in all 97 | output modes). 98 | 99 | For more pleasant output, you may wish to use string formatting to produce a limited number of significant digits:: 100 | 101 | >>> format(math.pi, '.12g') # give 12 significant digits 102 | '3.14159265359' 103 | 104 | >>> format(math.pi, '.2f') # give 2 digits after the point 105 | '3.14' 106 | 107 | >>> repr(math.pi) 108 | '3.141592653589793' 109 | 110 | 111 | It's important to realize that this is, in a real sense, an illusion: you're 112 | simply rounding the *display* of the true machine value. 113 | 114 | One illusion may beget another. For example, since 0.1 is not exactly 1/10, 115 | summing three values of 0.1 may not yield exactly 0.3, either:: 116 | 117 | >>> .1 + .1 + .1 == .3 118 | False 119 | 120 | Also, since the 0.1 cannot get any closer to the exact value of 1/10 and 121 | 0.3 cannot get any closer to the exact value of 3/10, then pre-rounding with 122 | :func:`round` function cannot help:: 123 | 124 | >>> round(.1, 1) + round(.1, 1) + round(.1, 1) == round(.3, 1) 125 | False 126 | 127 | Though the numbers cannot be made closer to their intended exact values, 128 | the :func:`round` function can be useful for post-rounding so that results 129 | with inexact values become comparable to one another:: 130 | 131 | >>> round(.1 + .1 + .1, 10) == round(.3, 10) 132 | True 133 | 134 | Binary floating-point arithmetic holds many surprises like this. The problem 135 | with "0.1" is explained in precise detail below, in the "Representation Error" 136 | section. See `The Perils of Floating Point `_ 137 | for a more complete account of other common surprises. 138 | 139 | As that says near the end, "there are no easy answers." Still, don't be unduly 140 | wary of floating-point! The errors in Python float operations are inherited 141 | from the floating-point hardware, and on most machines are on the order of no 142 | more than 1 part in 2\*\*53 per operation. That's more than adequate for most 143 | tasks, but you do need to keep in mind that it's not decimal arithmetic and 144 | that every float operation can suffer a new rounding error. 145 | 146 | While pathological cases do exist, for most casual use of floating-point 147 | arithmetic you'll see the result you expect in the end if you simply round the 148 | display of your final results to the number of decimal digits you expect. 149 | :func:`str` usually suffices, and for finer control see the :meth:`str.format` 150 | method's format specifiers in :ref:`formatstrings`. 151 | 152 | For use cases which require exact decimal representation, try using the 153 | :mod:`decimal` module which implements decimal arithmetic suitable for 154 | accounting applications and high-precision applications. 155 | 156 | Another form of exact arithmetic is supported by the :mod:`fractions` module 157 | which implements arithmetic based on rational numbers (so the numbers like 158 | 1/3 can be represented exactly). 159 | 160 | If you are a heavy user of floating point operations you should take a look 161 | at the Numerical Python package and many other packages for mathematical and 162 | statistical operations supplied by the SciPy project. See . 163 | 164 | Python provides tools that may help on those rare occasions when you really 165 | *do* want to know the exact value of a float. The 166 | :meth:`float.as_integer_ratio` method expresses the value of a float as a 167 | fraction:: 168 | 169 | >>> x = 3.14159 170 | >>> x.as_integer_ratio() 171 | (3537115888337719, 1125899906842624) 172 | 173 | Since the ratio is exact, it can be used to losslessly recreate the 174 | original value:: 175 | 176 | >>> x == 3537115888337719 / 1125899906842624 177 | True 178 | 179 | The :meth:`float.hex` method expresses a float in hexadecimal (base 180 | 16), again giving the exact value stored by your computer:: 181 | 182 | >>> x.hex() 183 | '0x1.921f9f01b866ep+1' 184 | 185 | This precise hexadecimal representation can be used to reconstruct 186 | the float value exactly:: 187 | 188 | >>> x == float.fromhex('0x1.921f9f01b866ep+1') 189 | True 190 | 191 | Since the representation is exact, it is useful for reliably porting values 192 | across different versions of Python (platform independence) and exchanging 193 | data with other languages that support the same format (such as Java and C99). 194 | 195 | Another helpful tool is the :func:`math.fsum` function which helps mitigate 196 | loss-of-precision during summation. It tracks "lost digits" as values are 197 | added onto a running total. That can make a difference in overall accuracy 198 | so that the errors do not accumulate to the point where they affect the 199 | final total: 200 | 201 | >>> sum([0.1] * 10) == 1.0 202 | False 203 | >>> math.fsum([0.1] * 10) == 1.0 204 | True 205 | 206 | .. _tut-fp-error: 207 | 208 | Representation Error 209 | ==================== 210 | 211 | This section explains the "0.1" example in detail, and shows how you can perform 212 | an exact analysis of cases like this yourself. Basic familiarity with binary 213 | floating-point representation is assumed. 214 | 215 | :dfn:`Representation error` refers to the fact that some (most, actually) 216 | decimal fractions cannot be represented exactly as binary (base 2) fractions. 217 | This is the chief reason why Python (or Perl, C, C++, Java, Fortran, and many 218 | others) often won't display the exact decimal number you expect. 219 | 220 | Why is that? 1/10 is not exactly representable as a binary fraction. Almost all 221 | machines today (November 2000) use IEEE-754 floating point arithmetic, and 222 | almost all platforms map Python floats to IEEE-754 "double precision". 754 223 | doubles contain 53 bits of precision, so on input the computer strives to 224 | convert 0.1 to the closest fraction it can of the form *J*/2**\ *N* where *J* is 225 | an integer containing exactly 53 bits. Rewriting :: 226 | 227 | 1 / 10 ~= J / (2**N) 228 | 229 | as :: 230 | 231 | J ~= 2**N / 10 232 | 233 | and recalling that *J* has exactly 53 bits (is ``>= 2**52`` but ``< 2**53``), 234 | the best value for *N* is 56:: 235 | 236 | >>> 2**52 <= 2**56 // 10 < 2**53 237 | True 238 | 239 | That is, 56 is the only value for *N* that leaves *J* with exactly 53 bits. The 240 | best possible value for *J* is then that quotient rounded:: 241 | 242 | >>> q, r = divmod(2**56, 10) 243 | >>> r 244 | 6 245 | 246 | Since the remainder is more than half of 10, the best approximation is obtained 247 | by rounding up:: 248 | 249 | >>> q+1 250 | 7205759403792794 251 | 252 | Therefore the best possible approximation to 1/10 in 754 double precision is:: 253 | 254 | 7205759403792794 / 2 ** 56 255 | 256 | Dividing both the numerator and denominator by two reduces the fraction to:: 257 | 258 | 3602879701896397 / 2 ** 55 259 | 260 | Note that since we rounded up, this is actually a little bit larger than 1/10; 261 | if we had not rounded up, the quotient would have been a little bit smaller than 262 | 1/10. But in no case can it be *exactly* 1/10! 263 | 264 | So the computer never "sees" 1/10: what it sees is the exact fraction given 265 | above, the best 754 double approximation it can get:: 266 | 267 | >>> 0.1 * 2 ** 55 268 | 3602879701896397.0 269 | 270 | If we multiply that fraction by 10\*\*55, we can see the value out to 271 | 55 decimal digits:: 272 | 273 | >>> 3602879701896397 * 10 ** 55 // 2 ** 55 274 | 1000000000000000055511151231257827021181583404541015625 275 | 276 | meaning that the exact number stored in the computer is equal to 277 | the decimal value 0.1000000000000000055511151231257827021181583404541015625. 278 | Instead of displaying the full decimal value, many languages (including 279 | older versions of Python), round the result to 17 significant digits:: 280 | 281 | >>> format(0.1, '.17f') 282 | '0.10000000000000001' 283 | 284 | The :mod:`fractions` and :mod:`decimal` modules make these calculations 285 | easy:: 286 | 287 | >>> from decimal import Decimal 288 | >>> from fractions import Fraction 289 | 290 | >>> Fraction.from_float(0.1) 291 | Fraction(3602879701896397, 36028797018963968) 292 | 293 | >>> (0.1).as_integer_ratio() 294 | (3602879701896397, 36028797018963968) 295 | 296 | >>> Decimal.from_float(0.1) 297 | Decimal('0.1000000000000000055511151231257827021181583404541015625') 298 | 299 | >>> format(Decimal.from_float(0.1), '.17') 300 | '0.10000000000000001' 301 | -------------------------------------------------------------------------------- /Pyhton-Official-Tutorial-html/_sources/index.rst.txt: -------------------------------------------------------------------------------- 1 | .. _tutorial-index: 2 | 3 | ###################### 4 | The Python Tutorial 5 | ###################### 6 | 7 | Python is an easy to learn, powerful programming language. It has efficient 8 | high-level data structures and a simple but effective approach to 9 | object-oriented programming. Python's elegant syntax and dynamic typing, 10 | together with its interpreted nature, make it an ideal language for scripting 11 | and rapid application development in many areas on most platforms. 12 | 13 | The Python interpreter and the extensive standard library are freely available 14 | in source or binary form for all major platforms from the Python Web site, 15 | https://www.python.org/, and may be freely distributed. The same site also 16 | contains distributions of and pointers to many free third party Python modules, 17 | programs and tools, and additional documentation. 18 | 19 | The Python interpreter is easily extended with new functions and data types 20 | implemented in C or C++ (or other languages callable from C). Python is also 21 | suitable as an extension language for customizable applications. 22 | 23 | This tutorial introduces the reader informally to the basic concepts and 24 | features of the Python language and system. It helps to have a Python 25 | interpreter handy for hands-on experience, but all examples are self-contained, 26 | so the tutorial can be read off-line as well. 27 | 28 | For a description of standard objects and modules, see :ref:`library-index`. 29 | :ref:`reference-index` gives a more formal definition of the language. To write 30 | extensions in C or C++, read :ref:`extending-index` and 31 | :ref:`c-api-index`. There are also several books covering Python in depth. 32 | 33 | This tutorial does not attempt to be comprehensive and cover every single 34 | feature, or even every commonly used feature. Instead, it introduces many of 35 | Python's most noteworthy features, and will give you a good idea of the 36 | language's flavor and style. After reading it, you will be able to read and 37 | write Python modules and programs, and you will be ready to learn more about the 38 | various Python library modules described in :ref:`library-index`. 39 | 40 | The :ref:`glossary` is also worth going through. 41 | 42 | .. toctree:: 43 | :numbered: 44 | 45 | appetite.rst 46 | interpreter.rst 47 | introduction.rst 48 | controlflow.rst 49 | datastructures.rst 50 | modules.rst 51 | inputoutput.rst 52 | errors.rst 53 | classes.rst 54 | stdlib.rst 55 | stdlib2.rst 56 | venv.rst 57 | whatnow.rst 58 | interactive.rst 59 | floatingpoint.rst 60 | appendix.rst 61 | -------------------------------------------------------------------------------- /Pyhton-Official-Tutorial-html/_sources/interactive.rst.txt: -------------------------------------------------------------------------------- 1 | .. _tut-interacting: 2 | 3 | ************************************************** 4 | Interactive Input Editing and History Substitution 5 | ************************************************** 6 | 7 | Some versions of the Python interpreter support editing of the current input 8 | line and history substitution, similar to facilities found in the Korn shell and 9 | the GNU Bash shell. This is implemented using the `GNU Readline`_ library, 10 | which supports various styles of editing. This library has its own 11 | documentation which we won't duplicate here. 12 | 13 | 14 | .. _tut-keybindings: 15 | 16 | Tab Completion and History Editing 17 | ================================== 18 | 19 | Completion of variable and module names is 20 | :ref:`automatically enabled ` at interpreter startup so 21 | that the :kbd:`Tab` key invokes the completion function; it looks at 22 | Python statement names, the current local variables, and the available 23 | module names. For dotted expressions such as ``string.a``, it will evaluate 24 | the expression up to the final ``'.'`` and then suggest completions from 25 | the attributes of the resulting object. Note that this may execute 26 | application-defined code if an object with a :meth:`__getattr__` method 27 | is part of the expression. The default configuration also saves your 28 | history into a file named :file:`.python_history` in your user directory. 29 | The history will be available again during the next interactive interpreter 30 | session. 31 | 32 | 33 | .. _tut-commentary: 34 | 35 | Alternatives to the Interactive Interpreter 36 | =========================================== 37 | 38 | This facility is an enormous step forward compared to earlier versions of the 39 | interpreter; however, some wishes are left: It would be nice if the proper 40 | indentation were suggested on continuation lines (the parser knows if an indent 41 | token is required next). The completion mechanism might use the interpreter's 42 | symbol table. A command to check (or even suggest) matching parentheses, 43 | quotes, etc., would also be useful. 44 | 45 | One alternative enhanced interactive interpreter that has been around for quite 46 | some time is IPython_, which features tab completion, object exploration and 47 | advanced history management. It can also be thoroughly customized and embedded 48 | into other applications. Another similar enhanced interactive environment is 49 | bpython_. 50 | 51 | 52 | .. _GNU Readline: https://tiswww.case.edu/php/chet/readline/rltop.html 53 | .. _IPython: https://ipython.org/ 54 | .. _bpython: https://www.bpython-interpreter.org/ 55 | -------------------------------------------------------------------------------- /Pyhton-Official-Tutorial-html/_sources/interpreter.rst.txt: -------------------------------------------------------------------------------- 1 | .. _tut-using: 2 | 3 | **************************** 4 | Using the Python Interpreter 5 | **************************** 6 | 7 | 8 | .. _tut-invoking: 9 | 10 | Invoking the Interpreter 11 | ======================== 12 | 13 | The Python interpreter is usually installed as :file:`/usr/local/bin/python3.8` 14 | on those machines where it is available; putting :file:`/usr/local/bin` in your 15 | Unix shell's search path makes it possible to start it by typing the command: 16 | 17 | .. code-block:: text 18 | 19 | python3.8 20 | 21 | to the shell. [#]_ Since the choice of the directory where the interpreter lives 22 | is an installation option, other places are possible; check with your local 23 | Python guru or system administrator. (E.g., :file:`/usr/local/python` is a 24 | popular alternative location.) 25 | 26 | On Windows machines, the Python installation is usually placed in 27 | :file:`C:\\Python36`, though you can change this when you're running the 28 | installer. To add this directory to your path, you can type the following 29 | command into the command prompt in a DOS box:: 30 | 31 | set path=%path%;C:\python36 32 | 33 | Typing an end-of-file character (:kbd:`Control-D` on Unix, :kbd:`Control-Z` on 34 | Windows) at the primary prompt causes the interpreter to exit with a zero exit 35 | status. If that doesn't work, you can exit the interpreter by typing the 36 | following command: ``quit()``. 37 | 38 | The interpreter's line-editing features include interactive editing, history 39 | substitution and code completion on systems that support readline. Perhaps the 40 | quickest check to see whether command line editing is supported is typing 41 | :kbd:`Control-P` to the first Python prompt you get. If it beeps, you have command 42 | line editing; see Appendix :ref:`tut-interacting` for an introduction to the 43 | keys. If nothing appears to happen, or if ``^P`` is echoed, command line 44 | editing isn't available; you'll only be able to use backspace to remove 45 | characters from the current line. 46 | 47 | The interpreter operates somewhat like the Unix shell: when called with standard 48 | input connected to a tty device, it reads and executes commands interactively; 49 | when called with a file name argument or with a file as standard input, it reads 50 | and executes a *script* from that file. 51 | 52 | A second way of starting the interpreter is ``python -c command [arg] ...``, 53 | which executes the statement(s) in *command*, analogous to the shell's 54 | :option:`-c` option. Since Python statements often contain spaces or other 55 | characters that are special to the shell, it is usually advised to quote 56 | *command* in its entirety with single quotes. 57 | 58 | Some Python modules are also useful as scripts. These can be invoked using 59 | ``python -m module [arg] ...``, which executes the source file for *module* as 60 | if you had spelled out its full name on the command line. 61 | 62 | When a script file is used, it is sometimes useful to be able to run the script 63 | and enter interactive mode afterwards. This can be done by passing :option:`-i` 64 | before the script. 65 | 66 | All command line options are described in :ref:`using-on-general`. 67 | 68 | 69 | .. _tut-argpassing: 70 | 71 | Argument Passing 72 | ---------------- 73 | 74 | When known to the interpreter, the script name and additional arguments 75 | thereafter are turned into a list of strings and assigned to the ``argv`` 76 | variable in the ``sys`` module. You can access this list by executing ``import 77 | sys``. The length of the list is at least one; when no script and no arguments 78 | are given, ``sys.argv[0]`` is an empty string. When the script name is given as 79 | ``'-'`` (meaning standard input), ``sys.argv[0]`` is set to ``'-'``. When 80 | :option:`-c` *command* is used, ``sys.argv[0]`` is set to ``'-c'``. When 81 | :option:`-m` *module* is used, ``sys.argv[0]`` is set to the full name of the 82 | located module. Options found after :option:`-c` *command* or :option:`-m` 83 | *module* are not consumed by the Python interpreter's option processing but 84 | left in ``sys.argv`` for the command or module to handle. 85 | 86 | 87 | .. _tut-interactive: 88 | 89 | Interactive Mode 90 | ---------------- 91 | 92 | When commands are read from a tty, the interpreter is said to be in *interactive 93 | mode*. In this mode it prompts for the next command with the *primary prompt*, 94 | usually three greater-than signs (``>>>``); for continuation lines it prompts 95 | with the *secondary prompt*, by default three dots (``...``). The interpreter 96 | prints a welcome message stating its version number and a copyright notice 97 | before printing the first prompt: 98 | 99 | .. code-block:: shell-session 100 | 101 | $ python3.8 102 | Python 3.8 (default, Sep 16 2015, 09:25:04) 103 | [GCC 4.8.2] on linux 104 | Type "help", "copyright", "credits" or "license" for more information. 105 | >>> 106 | 107 | .. XXX update for new releases 108 | 109 | Continuation lines are needed when entering a multi-line construct. As an 110 | example, take a look at this :keyword:`if` statement:: 111 | 112 | >>> the_world_is_flat = True 113 | >>> if the_world_is_flat: 114 | ... print("Be careful not to fall off!") 115 | ... 116 | Be careful not to fall off! 117 | 118 | 119 | For more on interactive mode, see :ref:`tut-interac`. 120 | 121 | 122 | .. _tut-interp: 123 | 124 | The Interpreter and Its Environment 125 | =================================== 126 | 127 | 128 | .. _tut-source-encoding: 129 | 130 | Source Code Encoding 131 | -------------------- 132 | 133 | By default, Python source files are treated as encoded in UTF-8. In that 134 | encoding, characters of most languages in the world can be used simultaneously 135 | in string literals, identifiers and comments --- although the standard library 136 | only uses ASCII characters for identifiers, a convention that any portable code 137 | should follow. To display all these characters properly, your editor must 138 | recognize that the file is UTF-8, and it must use a font that supports all the 139 | characters in the file. 140 | 141 | To declare an encoding other than the default one, a special comment line 142 | should be added as the *first* line of the file. The syntax is as follows:: 143 | 144 | # -*- coding: encoding -*- 145 | 146 | where *encoding* is one of the valid :mod:`codecs` supported by Python. 147 | 148 | For example, to declare that Windows-1252 encoding is to be used, the first 149 | line of your source code file should be:: 150 | 151 | # -*- coding: cp1252 -*- 152 | 153 | One exception to the *first line* rule is when the source code starts with a 154 | :ref:`UNIX "shebang" line `. In this case, the encoding 155 | declaration should be added as the second line of the file. For example:: 156 | 157 | #!/usr/bin/env python3 158 | # -*- coding: cp1252 -*- 159 | 160 | .. rubric:: Footnotes 161 | 162 | .. [#] On Unix, the Python 3.x interpreter is by default not installed with the 163 | executable named ``python``, so that it does not conflict with a 164 | simultaneously installed Python 2.x executable. 165 | -------------------------------------------------------------------------------- /Pyhton-Official-Tutorial-html/_sources/stdlib.rst.txt: -------------------------------------------------------------------------------- 1 | .. _tut-brieftour: 2 | 3 | ********************************** 4 | Brief Tour of the Standard Library 5 | ********************************** 6 | 7 | 8 | .. _tut-os-interface: 9 | 10 | Operating System Interface 11 | ========================== 12 | 13 | The :mod:`os` module provides dozens of functions for interacting with the 14 | operating system:: 15 | 16 | >>> import os 17 | >>> os.getcwd() # Return the current working directory 18 | 'C:\\Python38' 19 | >>> os.chdir('/server/accesslogs') # Change current working directory 20 | >>> os.system('mkdir today') # Run the command mkdir in the system shell 21 | 0 22 | 23 | Be sure to use the ``import os`` style instead of ``from os import *``. This 24 | will keep :func:`os.open` from shadowing the built-in :func:`open` function which 25 | operates much differently. 26 | 27 | .. index:: builtin: help 28 | 29 | The built-in :func:`dir` and :func:`help` functions are useful as interactive 30 | aids for working with large modules like :mod:`os`:: 31 | 32 | >>> import os 33 | >>> dir(os) 34 | 35 | >>> help(os) 36 | 37 | 38 | For daily file and directory management tasks, the :mod:`shutil` module provides 39 | a higher level interface that is easier to use:: 40 | 41 | >>> import shutil 42 | >>> shutil.copyfile('data.db', 'archive.db') 43 | 'archive.db' 44 | >>> shutil.move('/build/executables', 'installdir') 45 | 'installdir' 46 | 47 | 48 | .. _tut-file-wildcards: 49 | 50 | File Wildcards 51 | ============== 52 | 53 | The :mod:`glob` module provides a function for making file lists from directory 54 | wildcard searches:: 55 | 56 | >>> import glob 57 | >>> glob.glob('*.py') 58 | ['primes.py', 'random.py', 'quote.py'] 59 | 60 | 61 | .. _tut-command-line-arguments: 62 | 63 | Command Line Arguments 64 | ====================== 65 | 66 | Common utility scripts often need to process command line arguments. These 67 | arguments are stored in the :mod:`sys` module's *argv* attribute as a list. For 68 | instance the following output results from running ``python demo.py one two 69 | three`` at the command line:: 70 | 71 | >>> import sys 72 | >>> print(sys.argv) 73 | ['demo.py', 'one', 'two', 'three'] 74 | 75 | The :mod:`getopt` module processes *sys.argv* using the conventions of the Unix 76 | :func:`getopt` function. More powerful and flexible command line processing is 77 | provided by the :mod:`argparse` module. 78 | 79 | 80 | .. _tut-stderr: 81 | 82 | Error Output Redirection and Program Termination 83 | ================================================ 84 | 85 | The :mod:`sys` module also has attributes for *stdin*, *stdout*, and *stderr*. 86 | The latter is useful for emitting warnings and error messages to make them 87 | visible even when *stdout* has been redirected:: 88 | 89 | >>> sys.stderr.write('Warning, log file not found starting a new one\n') 90 | Warning, log file not found starting a new one 91 | 92 | The most direct way to terminate a script is to use ``sys.exit()``. 93 | 94 | 95 | .. _tut-string-pattern-matching: 96 | 97 | String Pattern Matching 98 | ======================= 99 | 100 | The :mod:`re` module provides regular expression tools for advanced string 101 | processing. For complex matching and manipulation, regular expressions offer 102 | succinct, optimized solutions:: 103 | 104 | >>> import re 105 | >>> re.findall(r'\bf[a-z]*', 'which foot or hand fell fastest') 106 | ['foot', 'fell', 'fastest'] 107 | >>> re.sub(r'(\b[a-z]+) \1', r'\1', 'cat in the the hat') 108 | 'cat in the hat' 109 | 110 | When only simple capabilities are needed, string methods are preferred because 111 | they are easier to read and debug:: 112 | 113 | >>> 'tea for too'.replace('too', 'two') 114 | 'tea for two' 115 | 116 | 117 | .. _tut-mathematics: 118 | 119 | Mathematics 120 | =========== 121 | 122 | The :mod:`math` module gives access to the underlying C library functions for 123 | floating point math:: 124 | 125 | >>> import math 126 | >>> math.cos(math.pi / 4) 127 | 0.70710678118654757 128 | >>> math.log(1024, 2) 129 | 10.0 130 | 131 | The :mod:`random` module provides tools for making random selections:: 132 | 133 | >>> import random 134 | >>> random.choice(['apple', 'pear', 'banana']) 135 | 'apple' 136 | >>> random.sample(range(100), 10) # sampling without replacement 137 | [30, 83, 16, 4, 8, 81, 41, 50, 18, 33] 138 | >>> random.random() # random float 139 | 0.17970987693706186 140 | >>> random.randrange(6) # random integer chosen from range(6) 141 | 4 142 | 143 | The :mod:`statistics` module calculates basic statistical properties 144 | (the mean, median, variance, etc.) of numeric data:: 145 | 146 | >>> import statistics 147 | >>> data = [2.75, 1.75, 1.25, 0.25, 0.5, 1.25, 3.5] 148 | >>> statistics.mean(data) 149 | 1.6071428571428572 150 | >>> statistics.median(data) 151 | 1.25 152 | >>> statistics.variance(data) 153 | 1.3720238095238095 154 | 155 | The SciPy project has many other modules for numerical 156 | computations. 157 | 158 | .. _tut-internet-access: 159 | 160 | Internet Access 161 | =============== 162 | 163 | There are a number of modules for accessing the internet and processing internet 164 | protocols. Two of the simplest are :mod:`urllib.request` for retrieving data 165 | from URLs and :mod:`smtplib` for sending mail:: 166 | 167 | >>> from urllib.request import urlopen 168 | >>> with urlopen('http://tycho.usno.navy.mil/cgi-bin/timer.pl') as response: 169 | ... for line in response: 170 | ... line = line.decode('utf-8') # Decoding the binary data to text. 171 | ... if 'EST' in line or 'EDT' in line: # look for Eastern Time 172 | ... print(line) 173 | 174 |
Nov. 25, 09:43:32 PM EST 175 | 176 | >>> import smtplib 177 | >>> server = smtplib.SMTP('localhost') 178 | >>> server.sendmail('soothsayer@example.org', 'jcaesar@example.org', 179 | ... """To: jcaesar@example.org 180 | ... From: soothsayer@example.org 181 | ... 182 | ... Beware the Ides of March. 183 | ... """) 184 | >>> server.quit() 185 | 186 | (Note that the second example needs a mailserver running on localhost.) 187 | 188 | 189 | .. _tut-dates-and-times: 190 | 191 | Dates and Times 192 | =============== 193 | 194 | The :mod:`datetime` module supplies classes for manipulating dates and times in 195 | both simple and complex ways. While date and time arithmetic is supported, the 196 | focus of the implementation is on efficient member extraction for output 197 | formatting and manipulation. The module also supports objects that are timezone 198 | aware. :: 199 | 200 | >>> # dates are easily constructed and formatted 201 | >>> from datetime import date 202 | >>> now = date.today() 203 | >>> now 204 | datetime.date(2003, 12, 2) 205 | >>> now.strftime("%m-%d-%y. %d %b %Y is a %A on the %d day of %B.") 206 | '12-02-03. 02 Dec 2003 is a Tuesday on the 02 day of December.' 207 | 208 | >>> # dates support calendar arithmetic 209 | >>> birthday = date(1964, 7, 31) 210 | >>> age = now - birthday 211 | >>> age.days 212 | 14368 213 | 214 | 215 | .. _tut-data-compression: 216 | 217 | Data Compression 218 | ================ 219 | 220 | Common data archiving and compression formats are directly supported by modules 221 | including: :mod:`zlib`, :mod:`gzip`, :mod:`bz2`, :mod:`lzma`, :mod:`zipfile` and 222 | :mod:`tarfile`. :: 223 | 224 | >>> import zlib 225 | >>> s = b'witch which has which witches wrist watch' 226 | >>> len(s) 227 | 41 228 | >>> t = zlib.compress(s) 229 | >>> len(t) 230 | 37 231 | >>> zlib.decompress(t) 232 | b'witch which has which witches wrist watch' 233 | >>> zlib.crc32(s) 234 | 226805979 235 | 236 | 237 | .. _tut-performance-measurement: 238 | 239 | Performance Measurement 240 | ======================= 241 | 242 | Some Python users develop a deep interest in knowing the relative performance of 243 | different approaches to the same problem. Python provides a measurement tool 244 | that answers those questions immediately. 245 | 246 | For example, it may be tempting to use the tuple packing and unpacking feature 247 | instead of the traditional approach to swapping arguments. The :mod:`timeit` 248 | module quickly demonstrates a modest performance advantage:: 249 | 250 | >>> from timeit import Timer 251 | >>> Timer('t=a; a=b; b=t', 'a=1; b=2').timeit() 252 | 0.57535828626024577 253 | >>> Timer('a,b = b,a', 'a=1; b=2').timeit() 254 | 0.54962537085770791 255 | 256 | In contrast to :mod:`timeit`'s fine level of granularity, the :mod:`profile` and 257 | :mod:`pstats` modules provide tools for identifying time critical sections in 258 | larger blocks of code. 259 | 260 | 261 | .. _tut-quality-control: 262 | 263 | Quality Control 264 | =============== 265 | 266 | One approach for developing high quality software is to write tests for each 267 | function as it is developed and to run those tests frequently during the 268 | development process. 269 | 270 | The :mod:`doctest` module provides a tool for scanning a module and validating 271 | tests embedded in a program's docstrings. Test construction is as simple as 272 | cutting-and-pasting a typical call along with its results into the docstring. 273 | This improves the documentation by providing the user with an example and it 274 | allows the doctest module to make sure the code remains true to the 275 | documentation:: 276 | 277 | def average(values): 278 | """Computes the arithmetic mean of a list of numbers. 279 | 280 | >>> print(average([20, 30, 70])) 281 | 40.0 282 | """ 283 | return sum(values) / len(values) 284 | 285 | import doctest 286 | doctest.testmod() # automatically validate the embedded tests 287 | 288 | The :mod:`unittest` module is not as effortless as the :mod:`doctest` module, 289 | but it allows a more comprehensive set of tests to be maintained in a separate 290 | file:: 291 | 292 | import unittest 293 | 294 | class TestStatisticalFunctions(unittest.TestCase): 295 | 296 | def test_average(self): 297 | self.assertEqual(average([20, 30, 70]), 40.0) 298 | self.assertEqual(round(average([1, 5, 7]), 1), 4.3) 299 | with self.assertRaises(ZeroDivisionError): 300 | average([]) 301 | with self.assertRaises(TypeError): 302 | average(20, 30, 70) 303 | 304 | unittest.main() # Calling from the command line invokes all tests 305 | 306 | 307 | .. _tut-batteries-included: 308 | 309 | Batteries Included 310 | ================== 311 | 312 | Python has a "batteries included" philosophy. This is best seen through the 313 | sophisticated and robust capabilities of its larger packages. For example: 314 | 315 | * The :mod:`xmlrpc.client` and :mod:`xmlrpc.server` modules make implementing 316 | remote procedure calls into an almost trivial task. Despite the modules 317 | names, no direct knowledge or handling of XML is needed. 318 | 319 | * The :mod:`email` package is a library for managing email messages, including 320 | MIME and other :rfc:`2822`-based message documents. Unlike :mod:`smtplib` and 321 | :mod:`poplib` which actually send and receive messages, the email package has 322 | a complete toolset for building or decoding complex message structures 323 | (including attachments) and for implementing internet encoding and header 324 | protocols. 325 | 326 | * The :mod:`json` package provides robust support for parsing this 327 | popular data interchange format. The :mod:`csv` module supports 328 | direct reading and writing of files in Comma-Separated Value format, 329 | commonly supported by databases and spreadsheets. XML processing is 330 | supported by the :mod:`xml.etree.ElementTree`, :mod:`xml.dom` and 331 | :mod:`xml.sax` packages. Together, these modules and packages 332 | greatly simplify data interchange between Python applications and 333 | other tools. 334 | 335 | * The :mod:`sqlite3` module is a wrapper for the SQLite database 336 | library, providing a persistent database that can be updated and 337 | accessed using slightly nonstandard SQL syntax. 338 | 339 | * Internationalization is supported by a number of modules including 340 | :mod:`gettext`, :mod:`locale`, and the :mod:`codecs` package. 341 | -------------------------------------------------------------------------------- /Pyhton-Official-Tutorial-html/_sources/venv.rst.txt: -------------------------------------------------------------------------------- 1 | 2 | .. _tut-venv: 3 | 4 | ********************************* 5 | Virtual Environments and Packages 6 | ********************************* 7 | 8 | Introduction 9 | ============ 10 | 11 | Python applications will often use packages and modules that don't 12 | come as part of the standard library. Applications will sometimes 13 | need a specific version of a library, because the application may 14 | require that a particular bug has been fixed or the application may be 15 | written using an obsolete version of the library's interface. 16 | 17 | This means it may not be possible for one Python installation to meet 18 | the requirements of every application. If application A needs version 19 | 1.0 of a particular module but application B needs version 2.0, then 20 | the requirements are in conflict and installing either version 1.0 or 2.0 21 | will leave one application unable to run. 22 | 23 | The solution for this problem is to create a :term:`virtual environment`, a 24 | self-contained directory tree that contains a Python installation for a 25 | particular version of Python, plus a number of additional packages. 26 | 27 | Different applications can then use different virtual environments. 28 | To resolve the earlier example of conflicting requirements, 29 | application A can have its own virtual environment with version 1.0 30 | installed while application B has another virtual environment with version 2.0. 31 | If application B requires a library be upgraded to version 3.0, this will 32 | not affect application A's environment. 33 | 34 | 35 | Creating Virtual Environments 36 | ============================= 37 | 38 | The module used to create and manage virtual environments is called 39 | :mod:`venv`. :mod:`venv` will usually install the most recent version of 40 | Python that you have available. If you have multiple versions of Python on your 41 | system, you can select a specific Python version by running ``python3`` or 42 | whichever version you want. 43 | 44 | To create a virtual environment, decide upon a directory where you want to 45 | place it, and run the :mod:`venv` module as a script with the directory path:: 46 | 47 | python3 -m venv tutorial-env 48 | 49 | This will create the ``tutorial-env`` directory if it doesn't exist, 50 | and also create directories inside it containing a copy of the Python 51 | interpreter, the standard library, and various supporting files. 52 | 53 | Once you've created a virtual environment, you may activate it. 54 | 55 | On Windows, run:: 56 | 57 | tutorial-env\Scripts\activate.bat 58 | 59 | On Unix or MacOS, run:: 60 | 61 | source tutorial-env/bin/activate 62 | 63 | (This script is written for the bash shell. If you use the 64 | :program:`csh` or :program:`fish` shells, there are alternate 65 | ``activate.csh`` and ``activate.fish`` scripts you should use 66 | instead.) 67 | 68 | Activating the virtual environment will change your shell's prompt to show what 69 | virtual environment you're using, and modify the environment so that running 70 | ``python`` will get you that particular version and installation of Python. 71 | For example: 72 | 73 | .. code-block:: bash 74 | 75 | $ source ~/envs/tutorial-env/bin/activate 76 | (tutorial-env) $ python 77 | Python 3.5.1 (default, May 6 2016, 10:59:36) 78 | ... 79 | >>> import sys 80 | >>> sys.path 81 | ['', '/usr/local/lib/python35.zip', ..., 82 | '~/envs/tutorial-env/lib/python3.5/site-packages'] 83 | >>> 84 | 85 | 86 | Managing Packages with pip 87 | ========================== 88 | 89 | You can install, upgrade, and remove packages using a program called 90 | :program:`pip`. By default ``pip`` will install packages from the Python 91 | Package Index, . You can browse the Python 92 | Package Index by going to it in your web browser, or you can use ``pip``'s 93 | limited search feature: 94 | 95 | .. code-block:: bash 96 | 97 | (tutorial-env) $ pip search astronomy 98 | skyfield - Elegant astronomy for Python 99 | gary - Galactic astronomy and gravitational dynamics. 100 | novas - The United States Naval Observatory NOVAS astronomy library 101 | astroobs - Provides astronomy ephemeris to plan telescope observations 102 | PyAstronomy - A collection of astronomy related tools for Python. 103 | ... 104 | 105 | ``pip`` has a number of subcommands: "search", "install", "uninstall", 106 | "freeze", etc. (Consult the :ref:`installing-index` guide for 107 | complete documentation for ``pip``.) 108 | 109 | You can install the latest version of a package by specifying a package's name: 110 | 111 | .. code-block:: bash 112 | 113 | (tutorial-env) $ pip install novas 114 | Collecting novas 115 | Downloading novas-3.1.1.3.tar.gz (136kB) 116 | Installing collected packages: novas 117 | Running setup.py install for novas 118 | Successfully installed novas-3.1.1.3 119 | 120 | You can also install a specific version of a package by giving the 121 | package name followed by ``==`` and the version number: 122 | 123 | .. code-block:: bash 124 | 125 | (tutorial-env) $ pip install requests==2.6.0 126 | Collecting requests==2.6.0 127 | Using cached requests-2.6.0-py2.py3-none-any.whl 128 | Installing collected packages: requests 129 | Successfully installed requests-2.6.0 130 | 131 | If you re-run this command, ``pip`` will notice that the requested 132 | version is already installed and do nothing. You can supply a 133 | different version number to get that version, or you can run ``pip 134 | install --upgrade`` to upgrade the package to the latest version: 135 | 136 | .. code-block:: bash 137 | 138 | (tutorial-env) $ pip install --upgrade requests 139 | Collecting requests 140 | Installing collected packages: requests 141 | Found existing installation: requests 2.6.0 142 | Uninstalling requests-2.6.0: 143 | Successfully uninstalled requests-2.6.0 144 | Successfully installed requests-2.7.0 145 | 146 | ``pip uninstall`` followed by one or more package names will remove the 147 | packages from the virtual environment. 148 | 149 | ``pip show`` will display information about a particular package: 150 | 151 | .. code-block:: bash 152 | 153 | (tutorial-env) $ pip show requests 154 | --- 155 | Metadata-Version: 2.0 156 | Name: requests 157 | Version: 2.7.0 158 | Summary: Python HTTP for Humans. 159 | Home-page: http://python-requests.org 160 | Author: Kenneth Reitz 161 | Author-email: me@kennethreitz.com 162 | License: Apache 2.0 163 | Location: /Users/akuchling/envs/tutorial-env/lib/python3.4/site-packages 164 | Requires: 165 | 166 | ``pip list`` will display all of the packages installed in the virtual 167 | environment: 168 | 169 | .. code-block:: bash 170 | 171 | (tutorial-env) $ pip list 172 | novas (3.1.1.3) 173 | numpy (1.9.2) 174 | pip (7.0.3) 175 | requests (2.7.0) 176 | setuptools (16.0) 177 | 178 | ``pip freeze`` will produce a similar list of the installed packages, 179 | but the output uses the format that ``pip install`` expects. 180 | A common convention is to put this list in a ``requirements.txt`` file: 181 | 182 | .. code-block:: bash 183 | 184 | (tutorial-env) $ pip freeze > requirements.txt 185 | (tutorial-env) $ cat requirements.txt 186 | novas==3.1.1.3 187 | numpy==1.9.2 188 | requests==2.7.0 189 | 190 | The ``requirements.txt`` can then be committed to version control and 191 | shipped as part of an application. Users can then install all the 192 | necessary packages with ``install -r``: 193 | 194 | .. code-block:: bash 195 | 196 | (tutorial-env) $ pip install -r requirements.txt 197 | Collecting novas==3.1.1.3 (from -r requirements.txt (line 1)) 198 | ... 199 | Collecting numpy==1.9.2 (from -r requirements.txt (line 2)) 200 | ... 201 | Collecting requests==2.7.0 (from -r requirements.txt (line 3)) 202 | ... 203 | Installing collected packages: novas, numpy, requests 204 | Running setup.py install for novas 205 | Successfully installed novas-3.1.1.3 numpy-1.9.2 requests-2.7.0 206 | 207 | ``pip`` has many more options. Consult the :ref:`installing-index` 208 | guide for complete documentation for ``pip``. When you've written 209 | a package and want to make it available on the Python Package Index, 210 | consult the :ref:`distributing-index` guide. 211 | -------------------------------------------------------------------------------- /Pyhton-Official-Tutorial-html/_sources/whatnow.rst.txt: -------------------------------------------------------------------------------- 1 | .. _tut-whatnow: 2 | 3 | ********* 4 | What Now? 5 | ********* 6 | 7 | Reading this tutorial has probably reinforced your interest in using Python --- 8 | you should be eager to apply Python to solving your real-world problems. Where 9 | should you go to learn more? 10 | 11 | This tutorial is part of Python's documentation set. Some other documents in 12 | the set are: 13 | 14 | * :ref:`library-index`: 15 | 16 | You should browse through this manual, which gives complete (though terse) 17 | reference material about types, functions, and the modules in the standard 18 | library. The standard Python distribution includes a *lot* of additional code. 19 | There are modules to read Unix mailboxes, retrieve documents via HTTP, generate 20 | random numbers, parse command-line options, write CGI programs, compress data, 21 | and many other tasks. Skimming through the Library Reference will give you an 22 | idea of what's available. 23 | 24 | * :ref:`installing-index` explains how to install additional modules written 25 | by other Python users. 26 | 27 | * :ref:`reference-index`: A detailed explanation of Python's syntax and 28 | semantics. It's heavy reading, but is useful as a complete guide to the 29 | language itself. 30 | 31 | More Python resources: 32 | 33 | * https://www.python.org: The major Python Web site. It contains code, 34 | documentation, and pointers to Python-related pages around the Web. This Web 35 | site is mirrored in various places around the world, such as Europe, Japan, and 36 | Australia; a mirror may be faster than the main site, depending on your 37 | geographical location. 38 | 39 | * https://docs.python.org: Fast access to Python's documentation. 40 | 41 | * https://pypi.org: The Python Package Index, previously also nicknamed 42 | the Cheese Shop, is an index of user-created Python modules that are available 43 | for download. Once you begin releasing code, you can register it here so that 44 | others can find it. 45 | 46 | * https://code.activestate.com/recipes/langs/python/: The Python Cookbook is a 47 | sizable collection of code examples, larger modules, and useful scripts. 48 | Particularly notable contributions are collected in a book also titled Python 49 | Cookbook (O'Reilly & Associates, ISBN 0-596-00797-3.) 50 | 51 | * http://www.pyvideo.org collects links to Python-related videos from 52 | conferences and user-group meetings. 53 | 54 | * https://scipy.org: The Scientific Python project includes modules for fast 55 | array computations and manipulations plus a host of packages for such 56 | things as linear algebra, Fourier transforms, non-linear solvers, 57 | random number distributions, statistical analysis and the like. 58 | 59 | For Python-related questions and problem reports, you can post to the newsgroup 60 | :newsgroup:`comp.lang.python`, or send them to the mailing list at 61 | python-list@python.org. The newsgroup and mailing list are gatewayed, so 62 | messages posted to one will automatically be forwarded to the other. There are 63 | hundreds of postings a day, asking (and 64 | answering) questions, suggesting new features, and announcing new modules. 65 | Mailing list archives are available at https://mail.python.org/pipermail/. 66 | 67 | Before posting, be sure to check the list of 68 | :ref:`Frequently Asked Questions ` (also called the FAQ). The 69 | FAQ answers many of the questions that come up again and again, and may 70 | already contain the solution for your problem. 71 | -------------------------------------------------------------------------------- /Pyhton-Official-Tutorial-html/_static/ajax-loader.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaolai/the-python-tutorial-in-other-formats/49cf65d89a2b534fdea7b46ea60dedb51215a601/Pyhton-Official-Tutorial-html/_static/ajax-loader.gif -------------------------------------------------------------------------------- /Pyhton-Official-Tutorial-html/_static/alabaster.css: -------------------------------------------------------------------------------- 1 | @import url("basic.css"); 2 | 3 | /* -- page layout ----------------------------------------------------------- */ 4 | 5 | body { 6 | font-family: Georgia, serif; 7 | font-size: 17px; 8 | background-color: #fff; 9 | color: #000; 10 | margin: 0; 11 | padding: 0; 12 | } 13 | 14 | 15 | div.document { 16 | width: 940px; 17 | margin: 30px auto 0 auto; 18 | } 19 | 20 | div.documentwrapper { 21 | float: left; 22 | width: 100%; 23 | } 24 | 25 | div.bodywrapper { 26 | margin: 0 0 0 220px; 27 | } 28 | 29 | div.sphinxsidebar { 30 | width: 220px; 31 | font-size: 14px; 32 | line-height: 1.5; 33 | } 34 | 35 | hr { 36 | border: 1px solid #B1B4B6; 37 | } 38 | 39 | div.body { 40 | background-color: #fff; 41 | color: #3E4349; 42 | padding: 0 30px 0 30px; 43 | } 44 | 45 | div.body > .section { 46 | text-align: left; 47 | } 48 | 49 | div.footer { 50 | width: 940px; 51 | margin: 20px auto 30px auto; 52 | font-size: 14px; 53 | color: #888; 54 | text-align: right; 55 | } 56 | 57 | div.footer a { 58 | color: #888; 59 | } 60 | 61 | p.caption { 62 | font-family: inherit; 63 | font-size: inherit; 64 | } 65 | 66 | 67 | div.relations { 68 | display: none; 69 | } 70 | 71 | 72 | div.sphinxsidebar a { 73 | color: #444; 74 | text-decoration: none; 75 | border-bottom: 1px dotted #999; 76 | } 77 | 78 | div.sphinxsidebar a:hover { 79 | border-bottom: 1px solid #999; 80 | } 81 | 82 | div.sphinxsidebarwrapper { 83 | padding: 18px 10px; 84 | } 85 | 86 | div.sphinxsidebarwrapper p.logo { 87 | padding: 0; 88 | margin: -10px 0 0 0px; 89 | text-align: center; 90 | } 91 | 92 | div.sphinxsidebarwrapper h1.logo { 93 | margin-top: -10px; 94 | text-align: center; 95 | margin-bottom: 5px; 96 | text-align: left; 97 | } 98 | 99 | div.sphinxsidebarwrapper h1.logo-name { 100 | margin-top: 0px; 101 | } 102 | 103 | div.sphinxsidebarwrapper p.blurb { 104 | margin-top: 0; 105 | font-style: normal; 106 | } 107 | 108 | div.sphinxsidebar h3, 109 | div.sphinxsidebar h4 { 110 | font-family: Georgia, serif; 111 | color: #444; 112 | font-size: 24px; 113 | font-weight: normal; 114 | margin: 0 0 5px 0; 115 | padding: 0; 116 | } 117 | 118 | div.sphinxsidebar h4 { 119 | font-size: 20px; 120 | } 121 | 122 | div.sphinxsidebar h3 a { 123 | color: #444; 124 | } 125 | 126 | div.sphinxsidebar p.logo a, 127 | div.sphinxsidebar h3 a, 128 | div.sphinxsidebar p.logo a:hover, 129 | div.sphinxsidebar h3 a:hover { 130 | border: none; 131 | } 132 | 133 | div.sphinxsidebar p { 134 | color: #555; 135 | margin: 10px 0; 136 | } 137 | 138 | div.sphinxsidebar ul { 139 | margin: 10px 0; 140 | padding: 0; 141 | color: #000; 142 | } 143 | 144 | div.sphinxsidebar ul li.toctree-l1 > a { 145 | font-size: 120%; 146 | } 147 | 148 | div.sphinxsidebar ul li.toctree-l2 > a { 149 | font-size: 110%; 150 | } 151 | 152 | div.sphinxsidebar input { 153 | border: 1px solid #CCC; 154 | font-family: Georgia, serif; 155 | font-size: 1em; 156 | } 157 | 158 | div.sphinxsidebar hr { 159 | border: none; 160 | height: 1px; 161 | color: #AAA; 162 | background: #AAA; 163 | 164 | text-align: left; 165 | margin-left: 0; 166 | width: 50%; 167 | } 168 | 169 | div.sphinxsidebar .badge { 170 | border-bottom: none; 171 | } 172 | 173 | div.sphinxsidebar .badge:hover { 174 | border-bottom: none; 175 | } 176 | 177 | /* To address an issue with donation coming after search */ 178 | div.sphinxsidebar h3.donation { 179 | margin-top: 10px; 180 | } 181 | 182 | /* -- body styles ----------------------------------------------------------- */ 183 | 184 | a { 185 | color: #004B6B; 186 | text-decoration: underline; 187 | } 188 | 189 | a:hover { 190 | color: #6D4100; 191 | text-decoration: underline; 192 | } 193 | 194 | div.body h1, 195 | div.body h2, 196 | div.body h3, 197 | div.body h4, 198 | div.body h5, 199 | div.body h6 { 200 | font-family: Georgia, serif; 201 | font-weight: normal; 202 | margin: 30px 0px 10px 0px; 203 | padding: 0; 204 | } 205 | 206 | div.body h1 { margin-top: 0; padding-top: 0; font-size: 240%; } 207 | div.body h2 { font-size: 180%; } 208 | div.body h3 { font-size: 150%; } 209 | div.body h4 { font-size: 130%; } 210 | div.body h5 { font-size: 100%; } 211 | div.body h6 { font-size: 100%; } 212 | 213 | a.headerlink { 214 | color: #DDD; 215 | padding: 0 4px; 216 | text-decoration: none; 217 | } 218 | 219 | a.headerlink:hover { 220 | color: #444; 221 | background: #EAEAEA; 222 | } 223 | 224 | div.body p, div.body dd, div.body li { 225 | line-height: 1.4em; 226 | } 227 | 228 | div.admonition { 229 | margin: 20px 0px; 230 | padding: 10px 30px; 231 | background-color: #EEE; 232 | border: 1px solid #CCC; 233 | } 234 | 235 | div.admonition tt.xref, div.admonition code.xref, div.admonition a tt { 236 | background-color: #FBFBFB; 237 | border-bottom: 1px solid #fafafa; 238 | } 239 | 240 | div.admonition p.admonition-title { 241 | font-family: Georgia, serif; 242 | font-weight: normal; 243 | font-size: 24px; 244 | margin: 0 0 10px 0; 245 | padding: 0; 246 | line-height: 1; 247 | } 248 | 249 | div.admonition p.last { 250 | margin-bottom: 0; 251 | } 252 | 253 | div.highlight { 254 | background-color: #fff; 255 | } 256 | 257 | dt:target, .highlight { 258 | background: #FAF3E8; 259 | } 260 | 261 | div.warning { 262 | background-color: #FCC; 263 | border: 1px solid #FAA; 264 | } 265 | 266 | div.danger { 267 | background-color: #FCC; 268 | border: 1px solid #FAA; 269 | -moz-box-shadow: 2px 2px 4px #D52C2C; 270 | -webkit-box-shadow: 2px 2px 4px #D52C2C; 271 | box-shadow: 2px 2px 4px #D52C2C; 272 | } 273 | 274 | div.error { 275 | background-color: #FCC; 276 | border: 1px solid #FAA; 277 | -moz-box-shadow: 2px 2px 4px #D52C2C; 278 | -webkit-box-shadow: 2px 2px 4px #D52C2C; 279 | box-shadow: 2px 2px 4px #D52C2C; 280 | } 281 | 282 | div.caution { 283 | background-color: #FCC; 284 | border: 1px solid #FAA; 285 | } 286 | 287 | div.attention { 288 | background-color: #FCC; 289 | border: 1px solid #FAA; 290 | } 291 | 292 | div.important { 293 | background-color: #EEE; 294 | border: 1px solid #CCC; 295 | } 296 | 297 | div.note { 298 | background-color: #EEE; 299 | border: 1px solid #CCC; 300 | } 301 | 302 | div.tip { 303 | background-color: #EEE; 304 | border: 1px solid #CCC; 305 | } 306 | 307 | div.hint { 308 | background-color: #EEE; 309 | border: 1px solid #CCC; 310 | } 311 | 312 | div.seealso { 313 | background-color: #EEE; 314 | border: 1px solid #CCC; 315 | } 316 | 317 | div.topic { 318 | background-color: #EEE; 319 | } 320 | 321 | p.admonition-title { 322 | display: inline; 323 | } 324 | 325 | p.admonition-title:after { 326 | content: ":"; 327 | } 328 | 329 | pre, tt, code { 330 | font-family: 'Consolas', 'Menlo', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', monospace; 331 | font-size: 0.9em; 332 | } 333 | 334 | .hll { 335 | background-color: #FFC; 336 | margin: 0 -12px; 337 | padding: 0 12px; 338 | display: block; 339 | } 340 | 341 | img.screenshot { 342 | } 343 | 344 | tt.descname, tt.descclassname, code.descname, code.descclassname { 345 | font-size: 0.95em; 346 | } 347 | 348 | tt.descname, code.descname { 349 | padding-right: 0.08em; 350 | } 351 | 352 | img.screenshot { 353 | -moz-box-shadow: 2px 2px 4px #EEE; 354 | -webkit-box-shadow: 2px 2px 4px #EEE; 355 | box-shadow: 2px 2px 4px #EEE; 356 | } 357 | 358 | table.docutils { 359 | border: 1px solid #888; 360 | -moz-box-shadow: 2px 2px 4px #EEE; 361 | -webkit-box-shadow: 2px 2px 4px #EEE; 362 | box-shadow: 2px 2px 4px #EEE; 363 | } 364 | 365 | table.docutils td, table.docutils th { 366 | border: 1px solid #888; 367 | padding: 0.25em 0.7em; 368 | } 369 | 370 | table.field-list, table.footnote { 371 | border: none; 372 | -moz-box-shadow: none; 373 | -webkit-box-shadow: none; 374 | box-shadow: none; 375 | } 376 | 377 | table.footnote { 378 | margin: 15px 0; 379 | width: 100%; 380 | border: 1px solid #EEE; 381 | background: #FDFDFD; 382 | font-size: 0.9em; 383 | } 384 | 385 | table.footnote + table.footnote { 386 | margin-top: -15px; 387 | border-top: none; 388 | } 389 | 390 | table.field-list th { 391 | padding: 0 0.8em 0 0; 392 | } 393 | 394 | table.field-list td { 395 | padding: 0; 396 | } 397 | 398 | table.field-list p { 399 | margin-bottom: 0.8em; 400 | } 401 | 402 | /* Cloned from 403 | * https://github.com/sphinx-doc/sphinx/commit/ef60dbfce09286b20b7385333d63a60321784e68 404 | */ 405 | .field-name { 406 | -moz-hyphens: manual; 407 | -ms-hyphens: manual; 408 | -webkit-hyphens: manual; 409 | hyphens: manual; 410 | } 411 | 412 | table.footnote td.label { 413 | width: .1px; 414 | padding: 0.3em 0 0.3em 0.5em; 415 | } 416 | 417 | table.footnote td { 418 | padding: 0.3em 0.5em; 419 | } 420 | 421 | dl { 422 | margin: 0; 423 | padding: 0; 424 | } 425 | 426 | dl dd { 427 | margin-left: 30px; 428 | } 429 | 430 | blockquote { 431 | margin: 0 0 0 30px; 432 | padding: 0; 433 | } 434 | 435 | ul, ol { 436 | /* Matches the 30px from the narrow-screen "li > ul" selector below */ 437 | margin: 10px 0 10px 30px; 438 | padding: 0; 439 | } 440 | 441 | pre { 442 | background: #EEE; 443 | padding: 7px 30px; 444 | margin: 15px 0px; 445 | line-height: 1.3em; 446 | } 447 | 448 | div.viewcode-block:target { 449 | background: #ffd; 450 | } 451 | 452 | dl pre, blockquote pre, li pre { 453 | margin-left: 0; 454 | padding-left: 30px; 455 | } 456 | 457 | tt, code { 458 | background-color: #ecf0f3; 459 | color: #222; 460 | /* padding: 1px 2px; */ 461 | } 462 | 463 | tt.xref, code.xref, a tt { 464 | background-color: #FBFBFB; 465 | border-bottom: 1px solid #fff; 466 | } 467 | 468 | a.reference { 469 | text-decoration: none; 470 | border-bottom: 1px dotted #004B6B; 471 | } 472 | 473 | /* Don't put an underline on images */ 474 | a.image-reference, a.image-reference:hover { 475 | border-bottom: none; 476 | } 477 | 478 | a.reference:hover { 479 | border-bottom: 1px solid #6D4100; 480 | } 481 | 482 | a.footnote-reference { 483 | text-decoration: none; 484 | font-size: 0.7em; 485 | vertical-align: top; 486 | border-bottom: 1px dotted #004B6B; 487 | } 488 | 489 | a.footnote-reference:hover { 490 | border-bottom: 1px solid #6D4100; 491 | } 492 | 493 | a:hover tt, a:hover code { 494 | background: #EEE; 495 | } 496 | 497 | 498 | @media screen and (max-width: 870px) { 499 | 500 | div.sphinxsidebar { 501 | display: none; 502 | } 503 | 504 | div.document { 505 | width: 100%; 506 | 507 | } 508 | 509 | div.documentwrapper { 510 | margin-left: 0; 511 | margin-top: 0; 512 | margin-right: 0; 513 | margin-bottom: 0; 514 | } 515 | 516 | div.bodywrapper { 517 | margin-top: 0; 518 | margin-right: 0; 519 | margin-bottom: 0; 520 | margin-left: 0; 521 | } 522 | 523 | ul { 524 | margin-left: 0; 525 | } 526 | 527 | li > ul { 528 | /* Matches the 30px from the "ul, ol" selector above */ 529 | margin-left: 30px; 530 | } 531 | 532 | .document { 533 | width: auto; 534 | } 535 | 536 | .footer { 537 | width: auto; 538 | } 539 | 540 | .bodywrapper { 541 | margin: 0; 542 | } 543 | 544 | .footer { 545 | width: auto; 546 | } 547 | 548 | .github { 549 | display: none; 550 | } 551 | 552 | 553 | 554 | } 555 | 556 | 557 | 558 | @media screen and (max-width: 875px) { 559 | 560 | body { 561 | margin: 0; 562 | padding: 20px 30px; 563 | } 564 | 565 | div.documentwrapper { 566 | float: none; 567 | background: #fff; 568 | } 569 | 570 | div.sphinxsidebar { 571 | display: block; 572 | float: none; 573 | width: 102.5%; 574 | margin: 50px -30px -20px -30px; 575 | padding: 10px 20px; 576 | background: #333; 577 | color: #FFF; 578 | } 579 | 580 | div.sphinxsidebar h3, div.sphinxsidebar h4, div.sphinxsidebar p, 581 | div.sphinxsidebar h3 a { 582 | color: #fff; 583 | } 584 | 585 | div.sphinxsidebar a { 586 | color: #AAA; 587 | } 588 | 589 | div.sphinxsidebar p.logo { 590 | display: none; 591 | } 592 | 593 | div.document { 594 | width: 100%; 595 | margin: 0; 596 | } 597 | 598 | div.footer { 599 | display: none; 600 | } 601 | 602 | div.bodywrapper { 603 | margin: 0; 604 | } 605 | 606 | div.body { 607 | min-height: 0; 608 | padding: 0; 609 | } 610 | 611 | .rtd_doc_footer { 612 | display: none; 613 | } 614 | 615 | .document { 616 | width: auto; 617 | } 618 | 619 | .footer { 620 | width: auto; 621 | } 622 | 623 | .footer { 624 | width: auto; 625 | } 626 | 627 | .github { 628 | display: none; 629 | } 630 | } 631 | 632 | 633 | /* misc. */ 634 | 635 | .revsys-inline { 636 | display: none!important; 637 | } 638 | 639 | /* Make nested-list/multi-paragraph items look better in Releases changelog 640 | * pages. Without this, docutils' magical list fuckery causes inconsistent 641 | * formatting between different release sub-lists. 642 | */ 643 | div#changelog > div.section > ul > li > p:only-child { 644 | margin-bottom: 0; 645 | } 646 | 647 | /* Hide fugly table cell borders in ..bibliography:: directive output */ 648 | table.docutils.citation, table.docutils.citation td, table.docutils.citation th { 649 | border: none; 650 | /* Below needed in some edge cases; if not applied, bottom shadows appear */ 651 | -moz-box-shadow: none; 652 | -webkit-box-shadow: none; 653 | box-shadow: none; 654 | } 655 | 656 | 657 | /* relbar */ 658 | 659 | .related { 660 | line-height: 30px; 661 | width: 100%; 662 | font-size: 0.9rem; 663 | } 664 | 665 | .related.top { 666 | border-bottom: 1px solid #EEE; 667 | margin-bottom: 20px; 668 | } 669 | 670 | .related.bottom { 671 | border-top: 1px solid #EEE; 672 | } 673 | 674 | .related ul { 675 | padding: 0; 676 | margin: 0; 677 | list-style: none; 678 | } 679 | 680 | .related li { 681 | display: inline; 682 | } 683 | 684 | nav#rellinks { 685 | float: right; 686 | } 687 | 688 | nav#rellinks li+li:before { 689 | content: "|"; 690 | } 691 | 692 | nav#breadcrumbs li+li:before { 693 | content: "\00BB"; 694 | } 695 | 696 | /* Hide certain items when printing */ 697 | @media print { 698 | div.related { 699 | display: none; 700 | } 701 | } -------------------------------------------------------------------------------- /Pyhton-Official-Tutorial-html/_static/basic.css: -------------------------------------------------------------------------------- 1 | /* 2 | * basic.css 3 | * ~~~~~~~~~ 4 | * 5 | * Sphinx stylesheet -- basic theme. 6 | * 7 | * :copyright: Copyright 2007-2018 by the Sphinx team, see AUTHORS. 8 | * :license: BSD, see LICENSE for details. 9 | * 10 | */ 11 | 12 | /* -- main layout ----------------------------------------------------------- */ 13 | 14 | div.clearer { 15 | clear: both; 16 | } 17 | 18 | /* -- relbar ---------------------------------------------------------------- */ 19 | 20 | div.related { 21 | width: 100%; 22 | font-size: 90%; 23 | } 24 | 25 | div.related h3 { 26 | display: none; 27 | } 28 | 29 | div.related ul { 30 | margin: 0; 31 | padding: 0 0 0 10px; 32 | list-style: none; 33 | } 34 | 35 | div.related li { 36 | display: inline; 37 | } 38 | 39 | div.related li.right { 40 | float: right; 41 | margin-right: 5px; 42 | } 43 | 44 | /* -- sidebar --------------------------------------------------------------- */ 45 | 46 | div.sphinxsidebarwrapper { 47 | padding: 10px 5px 0 10px; 48 | } 49 | 50 | div.sphinxsidebar { 51 | float: left; 52 | width: 230px; 53 | margin-left: -100%; 54 | font-size: 90%; 55 | word-wrap: break-word; 56 | overflow-wrap : break-word; 57 | } 58 | 59 | div.sphinxsidebar ul { 60 | list-style: none; 61 | } 62 | 63 | div.sphinxsidebar ul ul, 64 | div.sphinxsidebar ul.want-points { 65 | margin-left: 20px; 66 | list-style: square; 67 | } 68 | 69 | div.sphinxsidebar ul ul { 70 | margin-top: 0; 71 | margin-bottom: 0; 72 | } 73 | 74 | div.sphinxsidebar form { 75 | margin-top: 10px; 76 | } 77 | 78 | div.sphinxsidebar input { 79 | border: 1px solid #98dbcc; 80 | font-family: sans-serif; 81 | font-size: 1em; 82 | } 83 | 84 | div.sphinxsidebar #searchbox form.search { 85 | overflow: hidden; 86 | } 87 | 88 | div.sphinxsidebar #searchbox input[type="text"] { 89 | float: left; 90 | width: 80%; 91 | padding: 0.25em; 92 | box-sizing: border-box; 93 | } 94 | 95 | div.sphinxsidebar #searchbox input[type="submit"] { 96 | float: left; 97 | width: 20%; 98 | border-left: none; 99 | padding: 0.25em; 100 | box-sizing: border-box; 101 | } 102 | 103 | 104 | img { 105 | border: 0; 106 | max-width: 100%; 107 | } 108 | 109 | /* -- search page ----------------------------------------------------------- */ 110 | 111 | ul.search { 112 | margin: 10px 0 0 20px; 113 | padding: 0; 114 | } 115 | 116 | ul.search li { 117 | padding: 5px 0 5px 20px; 118 | background-image: url(file.png); 119 | background-repeat: no-repeat; 120 | background-position: 0 7px; 121 | } 122 | 123 | ul.search li a { 124 | font-weight: bold; 125 | } 126 | 127 | ul.search li div.context { 128 | color: #888; 129 | margin: 2px 0 0 30px; 130 | text-align: left; 131 | } 132 | 133 | ul.keywordmatches li.goodmatch a { 134 | font-weight: bold; 135 | } 136 | 137 | /* -- index page ------------------------------------------------------------ */ 138 | 139 | table.contentstable { 140 | width: 90%; 141 | margin-left: auto; 142 | margin-right: auto; 143 | } 144 | 145 | table.contentstable p.biglink { 146 | line-height: 150%; 147 | } 148 | 149 | a.biglink { 150 | font-size: 1.3em; 151 | } 152 | 153 | span.linkdescr { 154 | font-style: italic; 155 | padding-top: 5px; 156 | font-size: 90%; 157 | } 158 | 159 | /* -- general index --------------------------------------------------------- */ 160 | 161 | table.indextable { 162 | width: 100%; 163 | } 164 | 165 | table.indextable td { 166 | text-align: left; 167 | vertical-align: top; 168 | } 169 | 170 | table.indextable ul { 171 | margin-top: 0; 172 | margin-bottom: 0; 173 | list-style-type: none; 174 | } 175 | 176 | table.indextable > tbody > tr > td > ul { 177 | padding-left: 0em; 178 | } 179 | 180 | table.indextable tr.pcap { 181 | height: 10px; 182 | } 183 | 184 | table.indextable tr.cap { 185 | margin-top: 10px; 186 | background-color: #f2f2f2; 187 | } 188 | 189 | img.toggler { 190 | margin-right: 3px; 191 | margin-top: 3px; 192 | cursor: pointer; 193 | } 194 | 195 | div.modindex-jumpbox { 196 | border-top: 1px solid #ddd; 197 | border-bottom: 1px solid #ddd; 198 | margin: 1em 0 1em 0; 199 | padding: 0.4em; 200 | } 201 | 202 | div.genindex-jumpbox { 203 | border-top: 1px solid #ddd; 204 | border-bottom: 1px solid #ddd; 205 | margin: 1em 0 1em 0; 206 | padding: 0.4em; 207 | } 208 | 209 | /* -- domain module index --------------------------------------------------- */ 210 | 211 | table.modindextable td { 212 | padding: 2px; 213 | border-collapse: collapse; 214 | } 215 | 216 | /* -- general body styles --------------------------------------------------- */ 217 | 218 | div.body { 219 | min-width: 450px; 220 | max-width: 800px; 221 | } 222 | 223 | div.body p, div.body dd, div.body li, div.body blockquote { 224 | -moz-hyphens: auto; 225 | -ms-hyphens: auto; 226 | -webkit-hyphens: auto; 227 | hyphens: auto; 228 | } 229 | 230 | a.headerlink { 231 | visibility: hidden; 232 | } 233 | 234 | h1:hover > a.headerlink, 235 | h2:hover > a.headerlink, 236 | h3:hover > a.headerlink, 237 | h4:hover > a.headerlink, 238 | h5:hover > a.headerlink, 239 | h6:hover > a.headerlink, 240 | dt:hover > a.headerlink, 241 | caption:hover > a.headerlink, 242 | p.caption:hover > a.headerlink, 243 | div.code-block-caption:hover > a.headerlink { 244 | visibility: visible; 245 | } 246 | 247 | div.body p.caption { 248 | text-align: inherit; 249 | } 250 | 251 | div.body td { 252 | text-align: left; 253 | } 254 | 255 | .first { 256 | margin-top: 0 !important; 257 | } 258 | 259 | p.rubric { 260 | margin-top: 30px; 261 | font-weight: bold; 262 | } 263 | 264 | img.align-left, .figure.align-left, object.align-left { 265 | clear: left; 266 | float: left; 267 | margin-right: 1em; 268 | } 269 | 270 | img.align-right, .figure.align-right, object.align-right { 271 | clear: right; 272 | float: right; 273 | margin-left: 1em; 274 | } 275 | 276 | img.align-center, .figure.align-center, object.align-center { 277 | display: block; 278 | margin-left: auto; 279 | margin-right: auto; 280 | } 281 | 282 | .align-left { 283 | text-align: left; 284 | } 285 | 286 | .align-center { 287 | text-align: center; 288 | } 289 | 290 | .align-right { 291 | text-align: right; 292 | } 293 | 294 | /* -- sidebars -------------------------------------------------------------- */ 295 | 296 | div.sidebar { 297 | margin: 0 0 0.5em 1em; 298 | border: 1px solid #ddb; 299 | padding: 7px 7px 0 7px; 300 | background-color: #ffe; 301 | width: 40%; 302 | float: right; 303 | } 304 | 305 | p.sidebar-title { 306 | font-weight: bold; 307 | } 308 | 309 | /* -- topics ---------------------------------------------------------------- */ 310 | 311 | div.topic { 312 | border: 1px solid #ccc; 313 | padding: 7px 7px 0 7px; 314 | margin: 10px 0 10px 0; 315 | } 316 | 317 | p.topic-title { 318 | font-size: 1.1em; 319 | font-weight: bold; 320 | margin-top: 10px; 321 | } 322 | 323 | /* -- admonitions ----------------------------------------------------------- */ 324 | 325 | div.admonition { 326 | margin-top: 10px; 327 | margin-bottom: 10px; 328 | padding: 7px; 329 | } 330 | 331 | div.admonition dt { 332 | font-weight: bold; 333 | } 334 | 335 | div.admonition dl { 336 | margin-bottom: 0; 337 | } 338 | 339 | p.admonition-title { 340 | margin: 0px 10px 5px 0px; 341 | font-weight: bold; 342 | } 343 | 344 | div.body p.centered { 345 | text-align: center; 346 | margin-top: 25px; 347 | } 348 | 349 | /* -- tables ---------------------------------------------------------------- */ 350 | 351 | table.docutils { 352 | border: 0; 353 | border-collapse: collapse; 354 | } 355 | 356 | table.align-center { 357 | margin-left: auto; 358 | margin-right: auto; 359 | } 360 | 361 | table caption span.caption-number { 362 | font-style: italic; 363 | } 364 | 365 | table caption span.caption-text { 366 | } 367 | 368 | table.docutils td, table.docutils th { 369 | padding: 1px 8px 1px 5px; 370 | border-top: 0; 371 | border-left: 0; 372 | border-right: 0; 373 | border-bottom: 1px solid #aaa; 374 | } 375 | 376 | table.footnote td, table.footnote th { 377 | border: 0 !important; 378 | } 379 | 380 | th { 381 | text-align: left; 382 | padding-right: 5px; 383 | } 384 | 385 | table.citation { 386 | border-left: solid 1px gray; 387 | margin-left: 1px; 388 | } 389 | 390 | table.citation td { 391 | border-bottom: none; 392 | } 393 | 394 | /* -- figures --------------------------------------------------------------- */ 395 | 396 | div.figure { 397 | margin: 0.5em; 398 | padding: 0.5em; 399 | } 400 | 401 | div.figure p.caption { 402 | padding: 0.3em; 403 | } 404 | 405 | div.figure p.caption span.caption-number { 406 | font-style: italic; 407 | } 408 | 409 | div.figure p.caption span.caption-text { 410 | } 411 | 412 | /* -- field list styles ----------------------------------------------------- */ 413 | 414 | table.field-list td, table.field-list th { 415 | border: 0 !important; 416 | } 417 | 418 | .field-list ul { 419 | margin: 0; 420 | padding-left: 1em; 421 | } 422 | 423 | .field-list p { 424 | margin: 0; 425 | } 426 | 427 | .field-name { 428 | -moz-hyphens: manual; 429 | -ms-hyphens: manual; 430 | -webkit-hyphens: manual; 431 | hyphens: manual; 432 | } 433 | 434 | /* -- hlist styles ---------------------------------------------------------- */ 435 | 436 | table.hlist td { 437 | vertical-align: top; 438 | } 439 | 440 | 441 | /* -- other body styles ----------------------------------------------------- */ 442 | 443 | ol.arabic { 444 | list-style: decimal; 445 | } 446 | 447 | ol.loweralpha { 448 | list-style: lower-alpha; 449 | } 450 | 451 | ol.upperalpha { 452 | list-style: upper-alpha; 453 | } 454 | 455 | ol.lowerroman { 456 | list-style: lower-roman; 457 | } 458 | 459 | ol.upperroman { 460 | list-style: upper-roman; 461 | } 462 | 463 | dl { 464 | margin-bottom: 15px; 465 | } 466 | 467 | dd p { 468 | margin-top: 0px; 469 | } 470 | 471 | dd ul, dd table { 472 | margin-bottom: 10px; 473 | } 474 | 475 | dd { 476 | margin-top: 3px; 477 | margin-bottom: 10px; 478 | margin-left: 30px; 479 | } 480 | 481 | dt:target, span.highlighted { 482 | background-color: #fbe54e; 483 | } 484 | 485 | rect.highlighted { 486 | fill: #fbe54e; 487 | } 488 | 489 | dl.glossary dt { 490 | font-weight: bold; 491 | font-size: 1.1em; 492 | } 493 | 494 | .optional { 495 | font-size: 1.3em; 496 | } 497 | 498 | .sig-paren { 499 | font-size: larger; 500 | } 501 | 502 | .versionmodified { 503 | font-style: italic; 504 | } 505 | 506 | .system-message { 507 | background-color: #fda; 508 | padding: 5px; 509 | border: 3px solid red; 510 | } 511 | 512 | .footnote:target { 513 | background-color: #ffa; 514 | } 515 | 516 | .line-block { 517 | display: block; 518 | margin-top: 1em; 519 | margin-bottom: 1em; 520 | } 521 | 522 | .line-block .line-block { 523 | margin-top: 0; 524 | margin-bottom: 0; 525 | margin-left: 1.5em; 526 | } 527 | 528 | .guilabel, .menuselection { 529 | font-family: sans-serif; 530 | } 531 | 532 | .accelerator { 533 | text-decoration: underline; 534 | } 535 | 536 | .classifier { 537 | font-style: oblique; 538 | } 539 | 540 | abbr, acronym { 541 | border-bottom: dotted 1px; 542 | cursor: help; 543 | } 544 | 545 | /* -- code displays --------------------------------------------------------- */ 546 | 547 | pre { 548 | overflow: auto; 549 | overflow-y: hidden; /* fixes display issues on Chrome browsers */ 550 | } 551 | 552 | span.pre { 553 | -moz-hyphens: none; 554 | -ms-hyphens: none; 555 | -webkit-hyphens: none; 556 | hyphens: none; 557 | } 558 | 559 | td.linenos pre { 560 | padding: 5px 0px; 561 | border: 0; 562 | background-color: transparent; 563 | color: #aaa; 564 | } 565 | 566 | table.highlighttable { 567 | margin-left: 0.5em; 568 | } 569 | 570 | table.highlighttable td { 571 | padding: 0 0.5em 0 0.5em; 572 | } 573 | 574 | div.code-block-caption { 575 | padding: 2px 5px; 576 | font-size: small; 577 | } 578 | 579 | div.code-block-caption code { 580 | background-color: transparent; 581 | } 582 | 583 | div.code-block-caption + div > div.highlight > pre { 584 | margin-top: 0; 585 | } 586 | 587 | div.code-block-caption span.caption-number { 588 | padding: 0.1em 0.3em; 589 | font-style: italic; 590 | } 591 | 592 | div.code-block-caption span.caption-text { 593 | } 594 | 595 | div.literal-block-wrapper { 596 | padding: 1em 1em 0; 597 | } 598 | 599 | div.literal-block-wrapper div.highlight { 600 | margin: 0; 601 | } 602 | 603 | code.descname { 604 | background-color: transparent; 605 | font-weight: bold; 606 | font-size: 1.2em; 607 | } 608 | 609 | code.descclassname { 610 | background-color: transparent; 611 | } 612 | 613 | code.xref, a code { 614 | background-color: transparent; 615 | font-weight: bold; 616 | } 617 | 618 | h1 code, h2 code, h3 code, h4 code, h5 code, h6 code { 619 | background-color: transparent; 620 | } 621 | 622 | .viewcode-link { 623 | float: right; 624 | } 625 | 626 | .viewcode-back { 627 | float: right; 628 | font-family: sans-serif; 629 | } 630 | 631 | div.viewcode-block:target { 632 | margin: -1px -10px; 633 | padding: 0 10px; 634 | } 635 | 636 | /* -- math display ---------------------------------------------------------- */ 637 | 638 | img.math { 639 | vertical-align: middle; 640 | } 641 | 642 | div.body div.math p { 643 | text-align: center; 644 | } 645 | 646 | span.eqno { 647 | float: right; 648 | } 649 | 650 | span.eqno a.headerlink { 651 | position: relative; 652 | left: 0px; 653 | z-index: 1; 654 | } 655 | 656 | div.math:hover a.headerlink { 657 | visibility: visible; 658 | } 659 | 660 | /* -- printout stylesheet --------------------------------------------------- */ 661 | 662 | @media print { 663 | div.document, 664 | div.documentwrapper, 665 | div.bodywrapper { 666 | margin: 0 !important; 667 | width: 100%; 668 | } 669 | 670 | div.sphinxsidebar, 671 | div.related, 672 | div.footer, 673 | #top-link { 674 | display: none; 675 | } 676 | } -------------------------------------------------------------------------------- /Pyhton-Official-Tutorial-html/_static/comment-bright.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaolai/the-python-tutorial-in-other-formats/49cf65d89a2b534fdea7b46ea60dedb51215a601/Pyhton-Official-Tutorial-html/_static/comment-bright.png -------------------------------------------------------------------------------- /Pyhton-Official-Tutorial-html/_static/comment-close.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaolai/the-python-tutorial-in-other-formats/49cf65d89a2b534fdea7b46ea60dedb51215a601/Pyhton-Official-Tutorial-html/_static/comment-close.png -------------------------------------------------------------------------------- /Pyhton-Official-Tutorial-html/_static/comment.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaolai/the-python-tutorial-in-other-formats/49cf65d89a2b534fdea7b46ea60dedb51215a601/Pyhton-Official-Tutorial-html/_static/comment.png -------------------------------------------------------------------------------- /Pyhton-Official-Tutorial-html/_static/custom.css: -------------------------------------------------------------------------------- 1 | /* This file intentionally left blank. */ 2 | -------------------------------------------------------------------------------- /Pyhton-Official-Tutorial-html/_static/doctools.js: -------------------------------------------------------------------------------- 1 | /* 2 | * doctools.js 3 | * ~~~~~~~~~~~ 4 | * 5 | * Sphinx JavaScript utilities for all documentation. 6 | * 7 | * :copyright: Copyright 2007-2018 by the Sphinx team, see AUTHORS. 8 | * :license: BSD, see LICENSE for details. 9 | * 10 | */ 11 | 12 | /** 13 | * select a different prefix for underscore 14 | */ 15 | $u = _.noConflict(); 16 | 17 | /** 18 | * make the code below compatible with browsers without 19 | * an installed firebug like debugger 20 | if (!window.console || !console.firebug) { 21 | var names = ["log", "debug", "info", "warn", "error", "assert", "dir", 22 | "dirxml", "group", "groupEnd", "time", "timeEnd", "count", "trace", 23 | "profile", "profileEnd"]; 24 | window.console = {}; 25 | for (var i = 0; i < names.length; ++i) 26 | window.console[names[i]] = function() {}; 27 | } 28 | */ 29 | 30 | /** 31 | * small helper function to urldecode strings 32 | */ 33 | jQuery.urldecode = function(x) { 34 | return decodeURIComponent(x).replace(/\+/g, ' '); 35 | }; 36 | 37 | /** 38 | * small helper function to urlencode strings 39 | */ 40 | jQuery.urlencode = encodeURIComponent; 41 | 42 | /** 43 | * This function returns the parsed url parameters of the 44 | * current request. Multiple values per key are supported, 45 | * it will always return arrays of strings for the value parts. 46 | */ 47 | jQuery.getQueryParameters = function(s) { 48 | if (typeof s === 'undefined') 49 | s = document.location.search; 50 | var parts = s.substr(s.indexOf('?') + 1).split('&'); 51 | var result = {}; 52 | for (var i = 0; i < parts.length; i++) { 53 | var tmp = parts[i].split('=', 2); 54 | var key = jQuery.urldecode(tmp[0]); 55 | var value = jQuery.urldecode(tmp[1]); 56 | if (key in result) 57 | result[key].push(value); 58 | else 59 | result[key] = [value]; 60 | } 61 | return result; 62 | }; 63 | 64 | /** 65 | * highlight a given string on a jquery object by wrapping it in 66 | * span elements with the given class name. 67 | */ 68 | jQuery.fn.highlightText = function(text, className) { 69 | function highlight(node, addItems) { 70 | if (node.nodeType === 3) { 71 | var val = node.nodeValue; 72 | var pos = val.toLowerCase().indexOf(text); 73 | if (pos >= 0 && 74 | !jQuery(node.parentNode).hasClass(className) && 75 | !jQuery(node.parentNode).hasClass("nohighlight")) { 76 | var span; 77 | var isInSVG = jQuery(node).closest("body, svg, foreignObject").is("svg"); 78 | if (isInSVG) { 79 | span = document.createElementNS("http://www.w3.org/2000/svg", "tspan"); 80 | } else { 81 | span = document.createElement("span"); 82 | span.className = className; 83 | } 84 | span.appendChild(document.createTextNode(val.substr(pos, text.length))); 85 | node.parentNode.insertBefore(span, node.parentNode.insertBefore( 86 | document.createTextNode(val.substr(pos + text.length)), 87 | node.nextSibling)); 88 | node.nodeValue = val.substr(0, pos); 89 | if (isInSVG) { 90 | var bbox = span.getBBox(); 91 | var rect = document.createElementNS("http://www.w3.org/2000/svg", "rect"); 92 | rect.x.baseVal.value = bbox.x; 93 | rect.y.baseVal.value = bbox.y; 94 | rect.width.baseVal.value = bbox.width; 95 | rect.height.baseVal.value = bbox.height; 96 | rect.setAttribute('class', className); 97 | var parentOfText = node.parentNode.parentNode; 98 | addItems.push({ 99 | "parent": node.parentNode, 100 | "target": rect}); 101 | } 102 | } 103 | } 104 | else if (!jQuery(node).is("button, select, textarea")) { 105 | jQuery.each(node.childNodes, function() { 106 | highlight(this, addItems); 107 | }); 108 | } 109 | } 110 | var addItems = []; 111 | var result = this.each(function() { 112 | highlight(this, addItems); 113 | }); 114 | for (var i = 0; i < addItems.length; ++i) { 115 | jQuery(addItems[i].parent).before(addItems[i].target); 116 | } 117 | return result; 118 | }; 119 | 120 | /* 121 | * backward compatibility for jQuery.browser 122 | * This will be supported until firefox bug is fixed. 123 | */ 124 | if (!jQuery.browser) { 125 | jQuery.uaMatch = function(ua) { 126 | ua = ua.toLowerCase(); 127 | 128 | var match = /(chrome)[ \/]([\w.]+)/.exec(ua) || 129 | /(webkit)[ \/]([\w.]+)/.exec(ua) || 130 | /(opera)(?:.*version|)[ \/]([\w.]+)/.exec(ua) || 131 | /(msie) ([\w.]+)/.exec(ua) || 132 | ua.indexOf("compatible") < 0 && /(mozilla)(?:.*? rv:([\w.]+)|)/.exec(ua) || 133 | []; 134 | 135 | return { 136 | browser: match[ 1 ] || "", 137 | version: match[ 2 ] || "0" 138 | }; 139 | }; 140 | jQuery.browser = {}; 141 | jQuery.browser[jQuery.uaMatch(navigator.userAgent).browser] = true; 142 | } 143 | 144 | /** 145 | * Small JavaScript module for the documentation. 146 | */ 147 | var Documentation = { 148 | 149 | init : function() { 150 | this.fixFirefoxAnchorBug(); 151 | this.highlightSearchWords(); 152 | this.initIndexTable(); 153 | if (DOCUMENTATION_OPTIONS.NAVIGATION_WITH_KEYS) { 154 | this.initOnKeyListeners(); 155 | } 156 | }, 157 | 158 | /** 159 | * i18n support 160 | */ 161 | TRANSLATIONS : {}, 162 | PLURAL_EXPR : function(n) { return n === 1 ? 0 : 1; }, 163 | LOCALE : 'unknown', 164 | 165 | // gettext and ngettext don't access this so that the functions 166 | // can safely bound to a different name (_ = Documentation.gettext) 167 | gettext : function(string) { 168 | var translated = Documentation.TRANSLATIONS[string]; 169 | if (typeof translated === 'undefined') 170 | return string; 171 | return (typeof translated === 'string') ? translated : translated[0]; 172 | }, 173 | 174 | ngettext : function(singular, plural, n) { 175 | var translated = Documentation.TRANSLATIONS[singular]; 176 | if (typeof translated === 'undefined') 177 | return (n == 1) ? singular : plural; 178 | return translated[Documentation.PLURALEXPR(n)]; 179 | }, 180 | 181 | addTranslations : function(catalog) { 182 | for (var key in catalog.messages) 183 | this.TRANSLATIONS[key] = catalog.messages[key]; 184 | this.PLURAL_EXPR = new Function('n', 'return +(' + catalog.plural_expr + ')'); 185 | this.LOCALE = catalog.locale; 186 | }, 187 | 188 | /** 189 | * add context elements like header anchor links 190 | */ 191 | addContextElements : function() { 192 | $('div[id] > :header:first').each(function() { 193 | $('\u00B6'). 194 | attr('href', '#' + this.id). 195 | attr('title', _('Permalink to this headline')). 196 | appendTo(this); 197 | }); 198 | $('dt[id]').each(function() { 199 | $('\u00B6'). 200 | attr('href', '#' + this.id). 201 | attr('title', _('Permalink to this definition')). 202 | appendTo(this); 203 | }); 204 | }, 205 | 206 | /** 207 | * workaround a firefox stupidity 208 | * see: https://bugzilla.mozilla.org/show_bug.cgi?id=645075 209 | */ 210 | fixFirefoxAnchorBug : function() { 211 | if (document.location.hash && $.browser.mozilla) 212 | window.setTimeout(function() { 213 | document.location.href += ''; 214 | }, 10); 215 | }, 216 | 217 | /** 218 | * highlight the search words provided in the url in the text 219 | */ 220 | highlightSearchWords : function() { 221 | var params = $.getQueryParameters(); 222 | var terms = (params.highlight) ? params.highlight[0].split(/\s+/) : []; 223 | if (terms.length) { 224 | var body = $('div.body'); 225 | if (!body.length) { 226 | body = $('body'); 227 | } 228 | window.setTimeout(function() { 229 | $.each(terms, function() { 230 | body.highlightText(this.toLowerCase(), 'highlighted'); 231 | }); 232 | }, 10); 233 | $('') 235 | .appendTo($('#searchbox')); 236 | } 237 | }, 238 | 239 | /** 240 | * init the domain index toggle buttons 241 | */ 242 | initIndexTable : function() { 243 | var togglers = $('img.toggler').click(function() { 244 | var src = $(this).attr('src'); 245 | var idnum = $(this).attr('id').substr(7); 246 | $('tr.cg-' + idnum).toggle(); 247 | if (src.substr(-9) === 'minus.png') 248 | $(this).attr('src', src.substr(0, src.length-9) + 'plus.png'); 249 | else 250 | $(this).attr('src', src.substr(0, src.length-8) + 'minus.png'); 251 | }).css('display', ''); 252 | if (DOCUMENTATION_OPTIONS.COLLAPSE_INDEX) { 253 | togglers.click(); 254 | } 255 | }, 256 | 257 | /** 258 | * helper function to hide the search marks again 259 | */ 260 | hideSearchWords : function() { 261 | $('#searchbox .highlight-link').fadeOut(300); 262 | $('span.highlighted').removeClass('highlighted'); 263 | }, 264 | 265 | /** 266 | * make the url absolute 267 | */ 268 | makeURL : function(relativeURL) { 269 | return DOCUMENTATION_OPTIONS.URL_ROOT + '/' + relativeURL; 270 | }, 271 | 272 | /** 273 | * get the current relative url 274 | */ 275 | getCurrentURL : function() { 276 | var path = document.location.pathname; 277 | var parts = path.split(/\//); 278 | $.each(DOCUMENTATION_OPTIONS.URL_ROOT.split(/\//), function() { 279 | if (this === '..') 280 | parts.pop(); 281 | }); 282 | var url = parts.join('/'); 283 | return path.substring(url.lastIndexOf('/') + 1, path.length - 1); 284 | }, 285 | 286 | initOnKeyListeners: function() { 287 | $(document).keyup(function(event) { 288 | var activeElementType = document.activeElement.tagName; 289 | // don't navigate when in search box or textarea 290 | if (activeElementType !== 'TEXTAREA' && activeElementType !== 'INPUT' && activeElementType !== 'SELECT') { 291 | switch (event.keyCode) { 292 | case 37: // left 293 | var prevHref = $('link[rel="prev"]').prop('href'); 294 | if (prevHref) { 295 | window.location.href = prevHref; 296 | return false; 297 | } 298 | case 39: // right 299 | var nextHref = $('link[rel="next"]').prop('href'); 300 | if (nextHref) { 301 | window.location.href = nextHref; 302 | return false; 303 | } 304 | } 305 | } 306 | }); 307 | } 308 | }; 309 | 310 | // quick alias for translations 311 | _ = Documentation.gettext; 312 | 313 | $(document).ready(function() { 314 | Documentation.init(); 315 | }); 316 | -------------------------------------------------------------------------------- /Pyhton-Official-Tutorial-html/_static/documentation_options.js: -------------------------------------------------------------------------------- 1 | var DOCUMENTATION_OPTIONS = { 2 | URL_ROOT: document.getElementById("documentation_options").getAttribute('data-url_root'), 3 | VERSION: '0.1', 4 | LANGUAGE: 'None', 5 | COLLAPSE_INDEX: false, 6 | FILE_SUFFIX: '.html', 7 | HAS_SOURCE: true, 8 | SOURCELINK_SUFFIX: '.txt', 9 | NAVIGATION_WITH_KEYS: false, 10 | SEARCH_LANGUAGE_STOP_WORDS: ["a","and","are","as","at","be","but","by","for","if","in","into","is","it","near","no","not","of","on","or","such","that","the","their","then","there","these","they","this","to","was","will","with"] 11 | }; 12 | 13 | 14 | 15 | /* Non-minified version JS is _stemmer.js if file is provided */ 16 | /** 17 | * Porter Stemmer 18 | */ 19 | var Stemmer = function() { 20 | 21 | var step2list = { 22 | ational: 'ate', 23 | tional: 'tion', 24 | enci: 'ence', 25 | anci: 'ance', 26 | izer: 'ize', 27 | bli: 'ble', 28 | alli: 'al', 29 | entli: 'ent', 30 | eli: 'e', 31 | ousli: 'ous', 32 | ization: 'ize', 33 | ation: 'ate', 34 | ator: 'ate', 35 | alism: 'al', 36 | iveness: 'ive', 37 | fulness: 'ful', 38 | ousness: 'ous', 39 | aliti: 'al', 40 | iviti: 'ive', 41 | biliti: 'ble', 42 | logi: 'log' 43 | }; 44 | 45 | var step3list = { 46 | icate: 'ic', 47 | ative: '', 48 | alize: 'al', 49 | iciti: 'ic', 50 | ical: 'ic', 51 | ful: '', 52 | ness: '' 53 | }; 54 | 55 | var c = "[^aeiou]"; // consonant 56 | var v = "[aeiouy]"; // vowel 57 | var C = c + "[^aeiouy]*"; // consonant sequence 58 | var V = v + "[aeiou]*"; // vowel sequence 59 | 60 | var mgr0 = "^(" + C + ")?" + V + C; // [C]VC... is m>0 61 | var meq1 = "^(" + C + ")?" + V + C + "(" + V + ")?$"; // [C]VC[V] is m=1 62 | var mgr1 = "^(" + C + ")?" + V + C + V + C; // [C]VCVC... is m>1 63 | var s_v = "^(" + C + ")?" + v; // vowel in stem 64 | 65 | this.stemWord = function (w) { 66 | var stem; 67 | var suffix; 68 | var firstch; 69 | var origword = w; 70 | 71 | if (w.length < 3) 72 | return w; 73 | 74 | var re; 75 | var re2; 76 | var re3; 77 | var re4; 78 | 79 | firstch = w.substr(0,1); 80 | if (firstch == "y") 81 | w = firstch.toUpperCase() + w.substr(1); 82 | 83 | // Step 1a 84 | re = /^(.+?)(ss|i)es$/; 85 | re2 = /^(.+?)([^s])s$/; 86 | 87 | if (re.test(w)) 88 | w = w.replace(re,"$1$2"); 89 | else if (re2.test(w)) 90 | w = w.replace(re2,"$1$2"); 91 | 92 | // Step 1b 93 | re = /^(.+?)eed$/; 94 | re2 = /^(.+?)(ed|ing)$/; 95 | if (re.test(w)) { 96 | var fp = re.exec(w); 97 | re = new RegExp(mgr0); 98 | if (re.test(fp[1])) { 99 | re = /.$/; 100 | w = w.replace(re,""); 101 | } 102 | } 103 | else if (re2.test(w)) { 104 | var fp = re2.exec(w); 105 | stem = fp[1]; 106 | re2 = new RegExp(s_v); 107 | if (re2.test(stem)) { 108 | w = stem; 109 | re2 = /(at|bl|iz)$/; 110 | re3 = new RegExp("([^aeiouylsz])\\1$"); 111 | re4 = new RegExp("^" + C + v + "[^aeiouwxy]$"); 112 | if (re2.test(w)) 113 | w = w + "e"; 114 | else if (re3.test(w)) { 115 | re = /.$/; 116 | w = w.replace(re,""); 117 | } 118 | else if (re4.test(w)) 119 | w = w + "e"; 120 | } 121 | } 122 | 123 | // Step 1c 124 | re = /^(.+?)y$/; 125 | if (re.test(w)) { 126 | var fp = re.exec(w); 127 | stem = fp[1]; 128 | re = new RegExp(s_v); 129 | if (re.test(stem)) 130 | w = stem + "i"; 131 | } 132 | 133 | // Step 2 134 | re = /^(.+?)(ational|tional|enci|anci|izer|bli|alli|entli|eli|ousli|ization|ation|ator|alism|iveness|fulness|ousness|aliti|iviti|biliti|logi)$/; 135 | if (re.test(w)) { 136 | var fp = re.exec(w); 137 | stem = fp[1]; 138 | suffix = fp[2]; 139 | re = new RegExp(mgr0); 140 | if (re.test(stem)) 141 | w = stem + step2list[suffix]; 142 | } 143 | 144 | // Step 3 145 | re = /^(.+?)(icate|ative|alize|iciti|ical|ful|ness)$/; 146 | if (re.test(w)) { 147 | var fp = re.exec(w); 148 | stem = fp[1]; 149 | suffix = fp[2]; 150 | re = new RegExp(mgr0); 151 | if (re.test(stem)) 152 | w = stem + step3list[suffix]; 153 | } 154 | 155 | // Step 4 156 | re = /^(.+?)(al|ance|ence|er|ic|able|ible|ant|ement|ment|ent|ou|ism|ate|iti|ous|ive|ize)$/; 157 | re2 = /^(.+?)(s|t)(ion)$/; 158 | if (re.test(w)) { 159 | var fp = re.exec(w); 160 | stem = fp[1]; 161 | re = new RegExp(mgr1); 162 | if (re.test(stem)) 163 | w = stem; 164 | } 165 | else if (re2.test(w)) { 166 | var fp = re2.exec(w); 167 | stem = fp[1] + fp[2]; 168 | re2 = new RegExp(mgr1); 169 | if (re2.test(stem)) 170 | w = stem; 171 | } 172 | 173 | // Step 5 174 | re = /^(.+?)e$/; 175 | if (re.test(w)) { 176 | var fp = re.exec(w); 177 | stem = fp[1]; 178 | re = new RegExp(mgr1); 179 | re2 = new RegExp(meq1); 180 | re3 = new RegExp("^" + C + v + "[^aeiouwxy]$"); 181 | if (re.test(stem) || (re2.test(stem) && !(re3.test(stem)))) 182 | w = stem; 183 | } 184 | re = /ll$/; 185 | re2 = new RegExp(mgr1); 186 | if (re.test(w) && re2.test(w)) { 187 | re = /.$/; 188 | w = w.replace(re,""); 189 | } 190 | 191 | // and turn initial Y back to y 192 | if (firstch == "y") 193 | w = firstch.toLowerCase() + w.substr(1); 194 | return w; 195 | } 196 | } 197 | 198 | 199 | 200 | 201 | 202 | var splitChars = (function() { 203 | var result = {}; 204 | var singles = [96, 180, 187, 191, 215, 247, 749, 885, 903, 907, 909, 930, 1014, 1648, 205 | 1748, 1809, 2416, 2473, 2481, 2526, 2601, 2609, 2612, 2615, 2653, 2702, 206 | 2706, 2729, 2737, 2740, 2857, 2865, 2868, 2910, 2928, 2948, 2961, 2971, 207 | 2973, 3085, 3089, 3113, 3124, 3213, 3217, 3241, 3252, 3295, 3341, 3345, 208 | 3369, 3506, 3516, 3633, 3715, 3721, 3736, 3744, 3748, 3750, 3756, 3761, 209 | 3781, 3912, 4239, 4347, 4681, 4695, 4697, 4745, 4785, 4799, 4801, 4823, 210 | 4881, 5760, 5901, 5997, 6313, 7405, 8024, 8026, 8028, 8030, 8117, 8125, 211 | 8133, 8181, 8468, 8485, 8487, 8489, 8494, 8527, 11311, 11359, 11687, 11695, 212 | 11703, 11711, 11719, 11727, 11735, 12448, 12539, 43010, 43014, 43019, 43587, 213 | 43696, 43713, 64286, 64297, 64311, 64317, 64319, 64322, 64325, 65141]; 214 | var i, j, start, end; 215 | for (i = 0; i < singles.length; i++) { 216 | result[singles[i]] = true; 217 | } 218 | var ranges = [[0, 47], [58, 64], [91, 94], [123, 169], [171, 177], [182, 184], [706, 709], 219 | [722, 735], [741, 747], [751, 879], [888, 889], [894, 901], [1154, 1161], 220 | [1318, 1328], [1367, 1368], [1370, 1376], [1416, 1487], [1515, 1519], [1523, 1568], 221 | [1611, 1631], [1642, 1645], [1750, 1764], [1767, 1773], [1789, 1790], [1792, 1807], 222 | [1840, 1868], [1958, 1968], [1970, 1983], [2027, 2035], [2038, 2041], [2043, 2047], 223 | [2070, 2073], [2075, 2083], [2085, 2087], [2089, 2307], [2362, 2364], [2366, 2383], 224 | [2385, 2391], [2402, 2405], [2419, 2424], [2432, 2436], [2445, 2446], [2449, 2450], 225 | [2483, 2485], [2490, 2492], [2494, 2509], [2511, 2523], [2530, 2533], [2546, 2547], 226 | [2554, 2564], [2571, 2574], [2577, 2578], [2618, 2648], [2655, 2661], [2672, 2673], 227 | [2677, 2692], [2746, 2748], [2750, 2767], [2769, 2783], [2786, 2789], [2800, 2820], 228 | [2829, 2830], [2833, 2834], [2874, 2876], [2878, 2907], [2914, 2917], [2930, 2946], 229 | [2955, 2957], [2966, 2968], [2976, 2978], [2981, 2983], [2987, 2989], [3002, 3023], 230 | [3025, 3045], [3059, 3076], [3130, 3132], [3134, 3159], [3162, 3167], [3170, 3173], 231 | [3184, 3191], [3199, 3204], [3258, 3260], [3262, 3293], [3298, 3301], [3312, 3332], 232 | [3386, 3388], [3390, 3423], [3426, 3429], [3446, 3449], [3456, 3460], [3479, 3481], 233 | [3518, 3519], [3527, 3584], [3636, 3647], [3655, 3663], [3674, 3712], [3717, 3718], 234 | [3723, 3724], [3726, 3731], [3752, 3753], [3764, 3772], [3774, 3775], [3783, 3791], 235 | [3802, 3803], [3806, 3839], [3841, 3871], [3892, 3903], [3949, 3975], [3980, 4095], 236 | [4139, 4158], [4170, 4175], [4182, 4185], [4190, 4192], [4194, 4196], [4199, 4205], 237 | [4209, 4212], [4226, 4237], [4250, 4255], [4294, 4303], [4349, 4351], [4686, 4687], 238 | [4702, 4703], [4750, 4751], [4790, 4791], [4806, 4807], [4886, 4887], [4955, 4968], 239 | [4989, 4991], [5008, 5023], [5109, 5120], [5741, 5742], [5787, 5791], [5867, 5869], 240 | [5873, 5887], [5906, 5919], [5938, 5951], [5970, 5983], [6001, 6015], [6068, 6102], 241 | [6104, 6107], [6109, 6111], [6122, 6127], [6138, 6159], [6170, 6175], [6264, 6271], 242 | [6315, 6319], [6390, 6399], [6429, 6469], [6510, 6511], [6517, 6527], [6572, 6592], 243 | [6600, 6607], [6619, 6655], [6679, 6687], [6741, 6783], [6794, 6799], [6810, 6822], 244 | [6824, 6916], [6964, 6980], [6988, 6991], [7002, 7042], [7073, 7085], [7098, 7167], 245 | [7204, 7231], [7242, 7244], [7294, 7400], [7410, 7423], [7616, 7679], [7958, 7959], 246 | [7966, 7967], [8006, 8007], [8014, 8015], [8062, 8063], [8127, 8129], [8141, 8143], 247 | [8148, 8149], [8156, 8159], [8173, 8177], [8189, 8303], [8306, 8307], [8314, 8318], 248 | [8330, 8335], [8341, 8449], [8451, 8454], [8456, 8457], [8470, 8472], [8478, 8483], 249 | [8506, 8507], [8512, 8516], [8522, 8525], [8586, 9311], [9372, 9449], [9472, 10101], 250 | [10132, 11263], [11493, 11498], [11503, 11516], [11518, 11519], [11558, 11567], 251 | [11622, 11630], [11632, 11647], [11671, 11679], [11743, 11822], [11824, 12292], 252 | [12296, 12320], [12330, 12336], [12342, 12343], [12349, 12352], [12439, 12444], 253 | [12544, 12548], [12590, 12592], [12687, 12689], [12694, 12703], [12728, 12783], 254 | [12800, 12831], [12842, 12880], [12896, 12927], [12938, 12976], [12992, 13311], 255 | [19894, 19967], [40908, 40959], [42125, 42191], [42238, 42239], [42509, 42511], 256 | [42540, 42559], [42592, 42593], [42607, 42622], [42648, 42655], [42736, 42774], 257 | [42784, 42785], [42889, 42890], [42893, 43002], [43043, 43055], [43062, 43071], 258 | [43124, 43137], [43188, 43215], [43226, 43249], [43256, 43258], [43260, 43263], 259 | [43302, 43311], [43335, 43359], [43389, 43395], [43443, 43470], [43482, 43519], 260 | [43561, 43583], [43596, 43599], [43610, 43615], [43639, 43641], [43643, 43647], 261 | [43698, 43700], [43703, 43704], [43710, 43711], [43715, 43738], [43742, 43967], 262 | [44003, 44015], [44026, 44031], [55204, 55215], [55239, 55242], [55292, 55295], 263 | [57344, 63743], [64046, 64047], [64110, 64111], [64218, 64255], [64263, 64274], 264 | [64280, 64284], [64434, 64466], [64830, 64847], [64912, 64913], [64968, 65007], 265 | [65020, 65135], [65277, 65295], [65306, 65312], [65339, 65344], [65371, 65381], 266 | [65471, 65473], [65480, 65481], [65488, 65489], [65496, 65497]]; 267 | for (i = 0; i < ranges.length; i++) { 268 | start = ranges[i][0]; 269 | end = ranges[i][1]; 270 | for (j = start; j <= end; j++) { 271 | result[j] = true; 272 | } 273 | } 274 | return result; 275 | })(); 276 | 277 | function splitQuery(query) { 278 | var result = []; 279 | var start = -1; 280 | for (var i = 0; i < query.length; i++) { 281 | if (splitChars[query.charCodeAt(i)]) { 282 | if (start !== -1) { 283 | result.push(query.slice(start, i)); 284 | start = -1; 285 | } 286 | } else if (start === -1) { 287 | start = i; 288 | } 289 | } 290 | if (start !== -1) { 291 | result.push(query.slice(start)); 292 | } 293 | return result; 294 | } 295 | 296 | 297 | -------------------------------------------------------------------------------- /Pyhton-Official-Tutorial-html/_static/down-pressed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaolai/the-python-tutorial-in-other-formats/49cf65d89a2b534fdea7b46ea60dedb51215a601/Pyhton-Official-Tutorial-html/_static/down-pressed.png -------------------------------------------------------------------------------- /Pyhton-Official-Tutorial-html/_static/down.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaolai/the-python-tutorial-in-other-formats/49cf65d89a2b534fdea7b46ea60dedb51215a601/Pyhton-Official-Tutorial-html/_static/down.png -------------------------------------------------------------------------------- /Pyhton-Official-Tutorial-html/_static/file.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaolai/the-python-tutorial-in-other-formats/49cf65d89a2b534fdea7b46ea60dedb51215a601/Pyhton-Official-Tutorial-html/_static/file.png -------------------------------------------------------------------------------- /Pyhton-Official-Tutorial-html/_static/minus.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaolai/the-python-tutorial-in-other-formats/49cf65d89a2b534fdea7b46ea60dedb51215a601/Pyhton-Official-Tutorial-html/_static/minus.png -------------------------------------------------------------------------------- /Pyhton-Official-Tutorial-html/_static/plus.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaolai/the-python-tutorial-in-other-formats/49cf65d89a2b534fdea7b46ea60dedb51215a601/Pyhton-Official-Tutorial-html/_static/plus.png -------------------------------------------------------------------------------- /Pyhton-Official-Tutorial-html/_static/pygments.css: -------------------------------------------------------------------------------- 1 | .highlight .hll { background-color: #ffffcc } 2 | .highlight { background: #f8f8f8; } 3 | .highlight .c { color: #8f5902; font-style: italic } /* Comment */ 4 | .highlight .err { color: #a40000; border: 1px solid #ef2929 } /* Error */ 5 | .highlight .g { color: #000000 } /* Generic */ 6 | .highlight .k { color: #004461; font-weight: bold } /* Keyword */ 7 | .highlight .l { color: #000000 } /* Literal */ 8 | .highlight .n { color: #000000 } /* Name */ 9 | .highlight .o { color: #582800 } /* Operator */ 10 | .highlight .x { color: #000000 } /* Other */ 11 | .highlight .p { color: #000000; font-weight: bold } /* Punctuation */ 12 | .highlight .ch { color: #8f5902; font-style: italic } /* Comment.Hashbang */ 13 | .highlight .cm { color: #8f5902; font-style: italic } /* Comment.Multiline */ 14 | .highlight .cp { color: #8f5902 } /* Comment.Preproc */ 15 | .highlight .cpf { color: #8f5902; font-style: italic } /* Comment.PreprocFile */ 16 | .highlight .c1 { color: #8f5902; font-style: italic } /* Comment.Single */ 17 | .highlight .cs { color: #8f5902; font-style: italic } /* Comment.Special */ 18 | .highlight .gd { color: #a40000 } /* Generic.Deleted */ 19 | .highlight .ge { color: #000000; font-style: italic } /* Generic.Emph */ 20 | .highlight .gr { color: #ef2929 } /* Generic.Error */ 21 | .highlight .gh { color: #000080; font-weight: bold } /* Generic.Heading */ 22 | .highlight .gi { color: #00A000 } /* Generic.Inserted */ 23 | .highlight .go { color: #888888 } /* Generic.Output */ 24 | .highlight .gp { color: #745334 } /* Generic.Prompt */ 25 | .highlight .gs { color: #000000; font-weight: bold } /* Generic.Strong */ 26 | .highlight .gu { color: #800080; font-weight: bold } /* Generic.Subheading */ 27 | .highlight .gt { color: #a40000; font-weight: bold } /* Generic.Traceback */ 28 | .highlight .kc { color: #004461; font-weight: bold } /* Keyword.Constant */ 29 | .highlight .kd { color: #004461; font-weight: bold } /* Keyword.Declaration */ 30 | .highlight .kn { color: #004461; font-weight: bold } /* Keyword.Namespace */ 31 | .highlight .kp { color: #004461; font-weight: bold } /* Keyword.Pseudo */ 32 | .highlight .kr { color: #004461; font-weight: bold } /* Keyword.Reserved */ 33 | .highlight .kt { color: #004461; font-weight: bold } /* Keyword.Type */ 34 | .highlight .ld { color: #000000 } /* Literal.Date */ 35 | .highlight .m { color: #990000 } /* Literal.Number */ 36 | .highlight .s { color: #4e9a06 } /* Literal.String */ 37 | .highlight .na { color: #c4a000 } /* Name.Attribute */ 38 | .highlight .nb { color: #004461 } /* Name.Builtin */ 39 | .highlight .nc { color: #000000 } /* Name.Class */ 40 | .highlight .no { color: #000000 } /* Name.Constant */ 41 | .highlight .nd { color: #888888 } /* Name.Decorator */ 42 | .highlight .ni { color: #ce5c00 } /* Name.Entity */ 43 | .highlight .ne { color: #cc0000; font-weight: bold } /* Name.Exception */ 44 | .highlight .nf { color: #000000 } /* Name.Function */ 45 | .highlight .nl { color: #f57900 } /* Name.Label */ 46 | .highlight .nn { color: #000000 } /* Name.Namespace */ 47 | .highlight .nx { color: #000000 } /* Name.Other */ 48 | .highlight .py { color: #000000 } /* Name.Property */ 49 | .highlight .nt { color: #004461; font-weight: bold } /* Name.Tag */ 50 | .highlight .nv { color: #000000 } /* Name.Variable */ 51 | .highlight .ow { color: #004461; font-weight: bold } /* Operator.Word */ 52 | .highlight .w { color: #f8f8f8; text-decoration: underline } /* Text.Whitespace */ 53 | .highlight .mb { color: #990000 } /* Literal.Number.Bin */ 54 | .highlight .mf { color: #990000 } /* Literal.Number.Float */ 55 | .highlight .mh { color: #990000 } /* Literal.Number.Hex */ 56 | .highlight .mi { color: #990000 } /* Literal.Number.Integer */ 57 | .highlight .mo { color: #990000 } /* Literal.Number.Oct */ 58 | .highlight .sa { color: #4e9a06 } /* Literal.String.Affix */ 59 | .highlight .sb { color: #4e9a06 } /* Literal.String.Backtick */ 60 | .highlight .sc { color: #4e9a06 } /* Literal.String.Char */ 61 | .highlight .dl { color: #4e9a06 } /* Literal.String.Delimiter */ 62 | .highlight .sd { color: #8f5902; font-style: italic } /* Literal.String.Doc */ 63 | .highlight .s2 { color: #4e9a06 } /* Literal.String.Double */ 64 | .highlight .se { color: #4e9a06 } /* Literal.String.Escape */ 65 | .highlight .sh { color: #4e9a06 } /* Literal.String.Heredoc */ 66 | .highlight .si { color: #4e9a06 } /* Literal.String.Interpol */ 67 | .highlight .sx { color: #4e9a06 } /* Literal.String.Other */ 68 | .highlight .sr { color: #4e9a06 } /* Literal.String.Regex */ 69 | .highlight .s1 { color: #4e9a06 } /* Literal.String.Single */ 70 | .highlight .ss { color: #4e9a06 } /* Literal.String.Symbol */ 71 | .highlight .bp { color: #3465a4 } /* Name.Builtin.Pseudo */ 72 | .highlight .fm { color: #000000 } /* Name.Function.Magic */ 73 | .highlight .vc { color: #000000 } /* Name.Variable.Class */ 74 | .highlight .vg { color: #000000 } /* Name.Variable.Global */ 75 | .highlight .vi { color: #000000 } /* Name.Variable.Instance */ 76 | .highlight .vm { color: #000000 } /* Name.Variable.Magic */ 77 | .highlight .il { color: #990000 } /* Literal.Number.Integer.Long */ -------------------------------------------------------------------------------- /Pyhton-Official-Tutorial-html/_static/underscore.js: -------------------------------------------------------------------------------- 1 | // Underscore.js 1.3.1 2 | // (c) 2009-2012 Jeremy Ashkenas, DocumentCloud Inc. 3 | // Underscore is freely distributable under the MIT license. 4 | // Portions of Underscore are inspired or borrowed from Prototype, 5 | // Oliver Steele's Functional, and John Resig's Micro-Templating. 6 | // For all details and documentation: 7 | // http://documentcloud.github.com/underscore 8 | (function(){function q(a,c,d){if(a===c)return a!==0||1/a==1/c;if(a==null||c==null)return a===c;if(a._chain)a=a._wrapped;if(c._chain)c=c._wrapped;if(a.isEqual&&b.isFunction(a.isEqual))return a.isEqual(c);if(c.isEqual&&b.isFunction(c.isEqual))return c.isEqual(a);var e=l.call(a);if(e!=l.call(c))return false;switch(e){case "[object String]":return a==String(c);case "[object Number]":return a!=+a?c!=+c:a==0?1/a==1/c:a==+c;case "[object Date]":case "[object Boolean]":return+a==+c;case "[object RegExp]":return a.source== 9 | c.source&&a.global==c.global&&a.multiline==c.multiline&&a.ignoreCase==c.ignoreCase}if(typeof a!="object"||typeof c!="object")return false;for(var f=d.length;f--;)if(d[f]==a)return true;d.push(a);var f=0,g=true;if(e=="[object Array]"){if(f=a.length,g=f==c.length)for(;f--;)if(!(g=f in a==f in c&&q(a[f],c[f],d)))break}else{if("constructor"in a!="constructor"in c||a.constructor!=c.constructor)return false;for(var h in a)if(b.has(a,h)&&(f++,!(g=b.has(c,h)&&q(a[h],c[h],d))))break;if(g){for(h in c)if(b.has(c, 10 | h)&&!f--)break;g=!f}}d.pop();return g}var r=this,G=r._,n={},k=Array.prototype,o=Object.prototype,i=k.slice,H=k.unshift,l=o.toString,I=o.hasOwnProperty,w=k.forEach,x=k.map,y=k.reduce,z=k.reduceRight,A=k.filter,B=k.every,C=k.some,p=k.indexOf,D=k.lastIndexOf,o=Array.isArray,J=Object.keys,s=Function.prototype.bind,b=function(a){return new m(a)};if(typeof exports!=="undefined"){if(typeof module!=="undefined"&&module.exports)exports=module.exports=b;exports._=b}else r._=b;b.VERSION="1.3.1";var j=b.each= 11 | b.forEach=function(a,c,d){if(a!=null)if(w&&a.forEach===w)a.forEach(c,d);else if(a.length===+a.length)for(var e=0,f=a.length;e2;a== 12 | null&&(a=[]);if(y&&a.reduce===y)return e&&(c=b.bind(c,e)),f?a.reduce(c,d):a.reduce(c);j(a,function(a,b,i){f?d=c.call(e,d,a,b,i):(d=a,f=true)});if(!f)throw new TypeError("Reduce of empty array with no initial value");return d};b.reduceRight=b.foldr=function(a,c,d,e){var f=arguments.length>2;a==null&&(a=[]);if(z&&a.reduceRight===z)return e&&(c=b.bind(c,e)),f?a.reduceRight(c,d):a.reduceRight(c);var g=b.toArray(a).reverse();e&&!f&&(c=b.bind(c,e));return f?b.reduce(g,c,d,e):b.reduce(g,c)};b.find=b.detect= 13 | function(a,c,b){var e;E(a,function(a,g,h){if(c.call(b,a,g,h))return e=a,true});return e};b.filter=b.select=function(a,c,b){var e=[];if(a==null)return e;if(A&&a.filter===A)return a.filter(c,b);j(a,function(a,g,h){c.call(b,a,g,h)&&(e[e.length]=a)});return e};b.reject=function(a,c,b){var e=[];if(a==null)return e;j(a,function(a,g,h){c.call(b,a,g,h)||(e[e.length]=a)});return e};b.every=b.all=function(a,c,b){var e=true;if(a==null)return e;if(B&&a.every===B)return a.every(c,b);j(a,function(a,g,h){if(!(e= 14 | e&&c.call(b,a,g,h)))return n});return e};var E=b.some=b.any=function(a,c,d){c||(c=b.identity);var e=false;if(a==null)return e;if(C&&a.some===C)return a.some(c,d);j(a,function(a,b,h){if(e||(e=c.call(d,a,b,h)))return n});return!!e};b.include=b.contains=function(a,c){var b=false;if(a==null)return b;return p&&a.indexOf===p?a.indexOf(c)!=-1:b=E(a,function(a){return a===c})};b.invoke=function(a,c){var d=i.call(arguments,2);return b.map(a,function(a){return(b.isFunction(c)?c||a:a[c]).apply(a,d)})};b.pluck= 15 | function(a,c){return b.map(a,function(a){return a[c]})};b.max=function(a,c,d){if(!c&&b.isArray(a))return Math.max.apply(Math,a);if(!c&&b.isEmpty(a))return-Infinity;var e={computed:-Infinity};j(a,function(a,b,h){b=c?c.call(d,a,b,h):a;b>=e.computed&&(e={value:a,computed:b})});return e.value};b.min=function(a,c,d){if(!c&&b.isArray(a))return Math.min.apply(Math,a);if(!c&&b.isEmpty(a))return Infinity;var e={computed:Infinity};j(a,function(a,b,h){b=c?c.call(d,a,b,h):a;bd?1:0}),"value")};b.groupBy=function(a,c){var d={},e=b.isFunction(c)?c:function(a){return a[c]};j(a,function(a,b){var c=e(a,b);(d[c]||(d[c]=[])).push(a)});return d};b.sortedIndex=function(a, 17 | c,d){d||(d=b.identity);for(var e=0,f=a.length;e>1;d(a[g])=0})})};b.difference=function(a){var c=b.flatten(i.call(arguments,1));return b.filter(a,function(a){return!b.include(c,a)})};b.zip=function(){for(var a=i.call(arguments),c=b.max(b.pluck(a,"length")),d=Array(c),e=0;e=0;d--)b=[a[d].apply(this,b)];return b[0]}}; 24 | b.after=function(a,b){return a<=0?b():function(){if(--a<1)return b.apply(this,arguments)}};b.keys=J||function(a){if(a!==Object(a))throw new TypeError("Invalid object");var c=[],d;for(d in a)b.has(a,d)&&(c[c.length]=d);return c};b.values=function(a){return b.map(a,b.identity)};b.functions=b.methods=function(a){var c=[],d;for(d in a)b.isFunction(a[d])&&c.push(d);return c.sort()};b.extend=function(a){j(i.call(arguments,1),function(b){for(var d in b)a[d]=b[d]});return a};b.defaults=function(a){j(i.call(arguments, 25 | 1),function(b){for(var d in b)a[d]==null&&(a[d]=b[d])});return a};b.clone=function(a){return!b.isObject(a)?a:b.isArray(a)?a.slice():b.extend({},a)};b.tap=function(a,b){b(a);return a};b.isEqual=function(a,b){return q(a,b,[])};b.isEmpty=function(a){if(b.isArray(a)||b.isString(a))return a.length===0;for(var c in a)if(b.has(a,c))return false;return true};b.isElement=function(a){return!!(a&&a.nodeType==1)};b.isArray=o||function(a){return l.call(a)=="[object Array]"};b.isObject=function(a){return a===Object(a)}; 26 | b.isArguments=function(a){return l.call(a)=="[object Arguments]"};if(!b.isArguments(arguments))b.isArguments=function(a){return!(!a||!b.has(a,"callee"))};b.isFunction=function(a){return l.call(a)=="[object Function]"};b.isString=function(a){return l.call(a)=="[object String]"};b.isNumber=function(a){return l.call(a)=="[object Number]"};b.isNaN=function(a){return a!==a};b.isBoolean=function(a){return a===true||a===false||l.call(a)=="[object Boolean]"};b.isDate=function(a){return l.call(a)=="[object Date]"}; 27 | b.isRegExp=function(a){return l.call(a)=="[object RegExp]"};b.isNull=function(a){return a===null};b.isUndefined=function(a){return a===void 0};b.has=function(a,b){return I.call(a,b)};b.noConflict=function(){r._=G;return this};b.identity=function(a){return a};b.times=function(a,b,d){for(var e=0;e/g,">").replace(/"/g,""").replace(/'/g,"'").replace(/\//g,"/")};b.mixin=function(a){j(b.functions(a), 28 | function(c){K(c,b[c]=a[c])})};var L=0;b.uniqueId=function(a){var b=L++;return a?a+b:b};b.templateSettings={evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,escape:/<%-([\s\S]+?)%>/g};var t=/.^/,u=function(a){return a.replace(/\\\\/g,"\\").replace(/\\'/g,"'")};b.template=function(a,c){var d=b.templateSettings,d="var __p=[],print=function(){__p.push.apply(__p,arguments);};with(obj||{}){__p.push('"+a.replace(/\\/g,"\\\\").replace(/'/g,"\\'").replace(d.escape||t,function(a,b){return"',_.escape("+ 29 | u(b)+"),'"}).replace(d.interpolate||t,function(a,b){return"',"+u(b)+",'"}).replace(d.evaluate||t,function(a,b){return"');"+u(b).replace(/[\r\n\t]/g," ")+";__p.push('"}).replace(/\r/g,"\\r").replace(/\n/g,"\\n").replace(/\t/g,"\\t")+"');}return __p.join('');",e=new Function("obj","_",d);return c?e(c,b):function(a){return e.call(this,a,b)}};b.chain=function(a){return b(a).chain()};var m=function(a){this._wrapped=a};b.prototype=m.prototype;var v=function(a,c){return c?b(a).chain():a},K=function(a,c){m.prototype[a]= 30 | function(){var a=i.call(arguments);H.call(a,this._wrapped);return v(c.apply(b,a),this._chain)}};b.mixin(b);j("pop,push,reverse,shift,sort,splice,unshift".split(","),function(a){var b=k[a];m.prototype[a]=function(){var d=this._wrapped;b.apply(d,arguments);var e=d.length;(a=="shift"||a=="splice")&&e===0&&delete d[0];return v(d,this._chain)}});j(["concat","join","slice"],function(a){var b=k[a];m.prototype[a]=function(){return v(b.apply(this._wrapped,arguments),this._chain)}});m.prototype.chain=function(){this._chain= 31 | true;return this};m.prototype.value=function(){return this._wrapped}}).call(this); 32 | -------------------------------------------------------------------------------- /Pyhton-Official-Tutorial-html/_static/up-pressed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaolai/the-python-tutorial-in-other-formats/49cf65d89a2b534fdea7b46ea60dedb51215a601/Pyhton-Official-Tutorial-html/_static/up-pressed.png -------------------------------------------------------------------------------- /Pyhton-Official-Tutorial-html/_static/up.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaolai/the-python-tutorial-in-other-formats/49cf65d89a2b534fdea7b46ea60dedb51215a601/Pyhton-Official-Tutorial-html/_static/up.png -------------------------------------------------------------------------------- /Pyhton-Official-Tutorial-html/appetite.html: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 1. Whetting Your Appetite — Python Official Tutorial 0.1 documentation 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 |
30 |
31 |
32 | 33 | 34 |
35 | 36 |
37 |

1. Whetting Your Appetite

38 |

If you do much work on computers, eventually you find that there’s some task 39 | you’d like to automate. For example, you may wish to perform a 40 | search-and-replace over a large number of text files, or rename and rearrange a 41 | bunch of photo files in a complicated way. Perhaps you’d like to write a small 42 | custom database, or a specialized GUI application, or a simple game.

43 |

If you’re a professional software developer, you may have to work with several 44 | C/C++/Java libraries but find the usual write/compile/test/re-compile cycle is 45 | too slow. Perhaps you’re writing a test suite for such a library and find 46 | writing the testing code a tedious task. Or maybe you’ve written a program that 47 | could use an extension language, and you don’t want to design and implement a 48 | whole new language for your application.

49 |

Python is just the language for you.

50 |

You could write a Unix shell script or Windows batch files for some of these 51 | tasks, but shell scripts are best at moving around files and changing text data, 52 | not well-suited for GUI applications or games. You could write a C/C++/Java 53 | program, but it can take a lot of development time to get even a first-draft 54 | program. Python is simpler to use, available on Windows, Mac OS X, and Unix 55 | operating systems, and will help you get the job done more quickly.

56 |

Python is simple to use, but it is a real programming language, offering much 57 | more structure and support for large programs than shell scripts or batch files 58 | can offer. On the other hand, Python also offers much more error checking than 59 | C, and, being a very-high-level language, it has high-level data types built 60 | in, such as flexible arrays and dictionaries. Because of its more general data 61 | types Python is applicable to a much larger problem domain than Awk or even 62 | Perl, yet many things are at least as easy in Python as in those languages.

63 |

Python allows you to split your program into modules that can be reused in other 64 | Python programs. It comes with a large collection of standard modules that you 65 | can use as the basis of your programs — or as examples to start learning to 66 | program in Python. Some of these modules provide things like file I/O, system 67 | calls, sockets, and even interfaces to graphical user interface toolkits like 68 | Tk.

69 |

Python is an interpreted language, which can save you considerable time during 70 | program development because no compilation and linking is necessary. The 71 | interpreter can be used interactively, which makes it easy to experiment with 72 | features of the language, to write throw-away programs, or to test functions 73 | during bottom-up program development. It is also a handy desk calculator.

74 |

Python enables programs to be written compactly and readably. Programs written 75 | in Python are typically much shorter than equivalent C, C++, or Java programs, 76 | for several reasons:

77 |
    78 |
  • the high-level data types allow you to express complex operations in a single 79 | statement;
  • 80 |
  • statement grouping is done by indentation instead of beginning and ending 81 | brackets;
  • 82 |
  • no variable or argument declarations are necessary.
  • 83 |
84 |

Python is extensible: if you know how to program in C it is easy to add a new 85 | built-in function or module to the interpreter, either to perform critical 86 | operations at maximum speed, or to link Python programs to libraries that may 87 | only be available in binary form (such as a vendor-specific graphics library). 88 | Once you are really hooked, you can link the Python interpreter into an 89 | application written in C and use it as an extension or command language for that 90 | application.

91 |

By the way, the language is named after the BBC show “Monty Python’s Flying 92 | Circus” and has nothing to do with reptiles. Making references to Monty 93 | Python skits in documentation is not only allowed, it is encouraged!

94 |

Now that you are all excited about Python, you’ll want to examine it in some 95 | more detail. Since the best way to learn a language is to use it, the tutorial 96 | invites you to play with the Python interpreter as you read.

97 |

In the next chapter, the mechanics of using the interpreter are explained. This 98 | is rather mundane information, but essential for trying out the examples shown 99 | later.

100 |

The rest of the tutorial introduces various features of the Python language and 101 | system through examples, beginning with simple expressions, statements and data 102 | types, through functions and modules, and finally touching upon advanced 103 | concepts like exceptions and user-defined classes.

104 |
105 | 106 | 107 |
108 | 109 |
110 |
111 | 173 |
174 |
175 | 186 | 187 | 188 | 189 | 190 | 191 | -------------------------------------------------------------------------------- /Pyhton-Official-Tutorial-html/genindex.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | 7 | 8 | 9 | 10 | Index — Python Official Tutorial 0.1 documentation 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 |
30 |
31 | 32 | 33 |
34 | 35 | 36 |

Index

37 | 38 |
39 | Symbols 40 | | _ 41 | | A 42 | | B 43 | | C 44 | | D 45 | | E 46 | | F 47 | | H 48 | | J 49 | | M 50 | | N 51 | | O 52 | | P 53 | | R 54 | | S 55 | 56 |
57 |

Symbols

58 | 59 | 82 | 98 |
99 | 100 |

_

101 | 102 | 106 |
107 | 108 |

A

109 | 110 | 119 |
    111 |
  • 112 | annotations 113 | 114 |
  • 118 |
120 | 121 |

B

122 | 123 | 134 | 143 |
    124 |
  • 125 | built-in function 126 | 127 |
      128 |
    • help 129 |
    • 130 |
    • open 131 |
    • 132 |
  • 133 |
    135 |
  • 136 | builtins 137 | 138 |
  • 142 |
144 | 145 |

C

146 | 147 | 156 |
    148 |
  • 149 | coding 150 | 151 |
      152 |
    • style 153 |
    • 154 |
  • 155 |
157 | 158 |

D

159 | 160 | 164 | 168 |
169 | 170 |

E

171 | 172 | 185 |
186 | 187 |

F

188 | 189 | 205 | 214 |
    190 |
  • 191 | file 192 | 193 |
  • 197 |
  • 198 | for 199 | 200 |
  • 204 |
    206 |
  • 207 | function 208 | 209 |
  • 213 |
215 | 216 |

H

217 | 218 | 227 |
228 | 229 |

J

230 | 231 | 240 |
    232 |
  • 233 | json 234 | 235 |
  • 239 |
241 | 242 |

M

243 | 244 | 260 | 275 |
    245 |
  • 246 | mangling 247 | 248 |
      249 |
    • name 250 |
    • 251 |
  • 252 |
  • 253 | method 254 | 255 |
  • 259 |
276 | 277 |

N

278 | 279 | 288 |
    280 |
  • 281 | name 282 | 283 |
  • 287 |
289 | 290 |

O

291 | 292 | 303 | 312 |
    293 |
  • 294 | object 295 | 296 |
  • 302 |
313 | 314 |

P

315 | 316 | 340 | 346 |
347 | 348 |

R

349 | 350 | 359 |
    351 |
  • 352 | RFC 353 | 354 |
  • 358 |
360 | 361 |

S

362 | 363 | 379 | 397 |
    364 |
  • 365 | search 366 | 367 |
  • 371 |
  • 372 | statement 373 | 374 |
      375 |
    • for 376 |
    • 377 |
  • 378 |
398 | 399 | 400 | 401 |
402 | 403 |
404 |
405 | 465 |
466 |
467 | 475 | 476 | 477 | 478 | 479 | 480 | -------------------------------------------------------------------------------- /Pyhton-Official-Tutorial-html/interactive.html: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 14. Interactive Input Editing and History Substitution — Python Official Tutorial 0.1 documentation 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 |
30 |
31 |
32 | 33 | 34 |
35 | 36 |
37 |

14. Interactive Input Editing and History Substitution

38 |

Some versions of the Python interpreter support editing of the current input 39 | line and history substitution, similar to facilities found in the Korn shell and 40 | the GNU Bash shell. This is implemented using the GNU Readline library, 41 | which supports various styles of editing. This library has its own 42 | documentation which we won’t duplicate here.

43 |
44 |

14.1. Tab Completion and History Editing

45 |

Completion of variable and module names is 46 | automatically enabled at interpreter startup so 47 | that the Tab key invokes the completion function; it looks at 48 | Python statement names, the current local variables, and the available 49 | module names. For dotted expressions such as string.a, it will evaluate 50 | the expression up to the final '.' and then suggest completions from 51 | the attributes of the resulting object. Note that this may execute 52 | application-defined code if an object with a __getattr__() method 53 | is part of the expression. The default configuration also saves your 54 | history into a file named .python_history in your user directory. 55 | The history will be available again during the next interactive interpreter 56 | session.

57 |
58 |
59 |

14.2. Alternatives to the Interactive Interpreter

60 |

This facility is an enormous step forward compared to earlier versions of the 61 | interpreter; however, some wishes are left: It would be nice if the proper 62 | indentation were suggested on continuation lines (the parser knows if an indent 63 | token is required next). The completion mechanism might use the interpreter’s 64 | symbol table. A command to check (or even suggest) matching parentheses, 65 | quotes, etc., would also be useful.

66 |

One alternative enhanced interactive interpreter that has been around for quite 67 | some time is IPython, which features tab completion, object exploration and 68 | advanced history management. It can also be thoroughly customized and embedded 69 | into other applications. Another similar enhanced interactive environment is 70 | bpython.

71 |
72 |
73 | 74 | 75 |
76 | 77 |
78 |
79 | 145 |
146 |
147 | 158 | 159 | 160 | 161 | 162 | 163 | -------------------------------------------------------------------------------- /Pyhton-Official-Tutorial-html/objects.inv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaolai/the-python-tutorial-in-other-formats/49cf65d89a2b534fdea7b46ea60dedb51215a601/Pyhton-Official-Tutorial-html/objects.inv -------------------------------------------------------------------------------- /Pyhton-Official-Tutorial-html/search.html: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | Search — Python Official Tutorial 0.1 documentation 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 |
37 |
38 |
39 | 40 | 41 |
42 | 43 |

Search

44 |
45 | 46 |

47 | Please activate JavaScript to enable the search 48 | functionality. 49 |

50 |
51 |

52 | From here you can search these documents. Enter your search 53 | words into the box below and click "search". Note that the search 54 | function will automatically search for all of the words. Pages 55 | containing fewer words won't appear in the result list. 56 |

57 |
58 | 59 | 60 | 61 |
62 | 63 |
64 | 65 |
66 | 67 |
68 | 69 |
70 |
71 | 119 |
120 |
121 | 129 | 130 | 131 | 132 | 133 | 134 | -------------------------------------------------------------------------------- /Pyhton-Official-Tutorial-html/whatnow.html: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 13. What Now? — Python Official Tutorial 0.1 documentation 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 |
30 |
31 |
32 | 33 | 34 |
35 | 36 |
37 |

13. What Now?

38 |

Reading this tutorial has probably reinforced your interest in using Python — 39 | you should be eager to apply Python to solving your real-world problems. Where 40 | should you go to learn more?

41 |

This tutorial is part of Python’s documentation set. Some other documents in 42 | the set are:

43 |
    44 |
  • The Python Standard Library:

    45 |

    You should browse through this manual, which gives complete (though terse) 46 | reference material about types, functions, and the modules in the standard 47 | library. The standard Python distribution includes a lot of additional code. 48 | There are modules to read Unix mailboxes, retrieve documents via HTTP, generate 49 | random numbers, parse command-line options, write CGI programs, compress data, 50 | and many other tasks. Skimming through the Library Reference will give you an 51 | idea of what’s available.

    52 |
  • 53 |
  • Installing Python Modules explains how to install additional modules written 54 | by other Python users.

    55 |
  • 56 |
  • The Python Language Reference: A detailed explanation of Python’s syntax and 57 | semantics. It’s heavy reading, but is useful as a complete guide to the 58 | language itself.

    59 |
  • 60 |
61 |

More Python resources:

62 |
    63 |
  • https://www.python.org: The major Python Web site. It contains code, 64 | documentation, and pointers to Python-related pages around the Web. This Web 65 | site is mirrored in various places around the world, such as Europe, Japan, and 66 | Australia; a mirror may be faster than the main site, depending on your 67 | geographical location.
  • 68 |
  • https://docs.python.org: Fast access to Python’s documentation.
  • 69 |
  • https://pypi.org: The Python Package Index, previously also nicknamed 70 | the Cheese Shop, is an index of user-created Python modules that are available 71 | for download. Once you begin releasing code, you can register it here so that 72 | others can find it.
  • 73 |
  • https://code.activestate.com/recipes/langs/python/: The Python Cookbook is a 74 | sizable collection of code examples, larger modules, and useful scripts. 75 | Particularly notable contributions are collected in a book also titled Python 76 | Cookbook (O’Reilly & Associates, ISBN 0-596-00797-3.)
  • 77 |
  • http://www.pyvideo.org collects links to Python-related videos from 78 | conferences and user-group meetings.
  • 79 |
  • https://scipy.org: The Scientific Python project includes modules for fast 80 | array computations and manipulations plus a host of packages for such 81 | things as linear algebra, Fourier transforms, non-linear solvers, 82 | random number distributions, statistical analysis and the like.
  • 83 |
84 |

For Python-related questions and problem reports, you can post to the newsgroup 85 | comp.lang.python, or send them to the mailing list at 86 | python-list@python.org. The newsgroup and mailing list are gatewayed, so 87 | messages posted to one will automatically be forwarded to the other. There are 88 | hundreds of postings a day, asking (and 89 | answering) questions, suggesting new features, and announcing new modules. 90 | Mailing list archives are available at https://mail.python.org/pipermail/.

91 |

Before posting, be sure to check the list of 92 | Frequently Asked Questions (also called the FAQ). The 93 | FAQ answers many of the questions that come up again and again, and may 94 | already contain the solution for your problem.

95 |
96 | 97 | 98 |
99 | 100 |
101 |
102 | 164 |
165 |
166 | 177 | 178 | 179 | 180 | 181 | 182 | -------------------------------------------------------------------------------- /Pyhton-Official-Tutorial-ipynb/appendix.rst.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "$$\n", 8 | "\\def\\CC{\\bf C}\n", 9 | "\\def\\QQ{\\bf Q}\n", 10 | "\\def\\RR{\\bf R}\n", 11 | "\\def\\ZZ{\\bf Z}\n", 12 | "\\def\\NN{\\bf N}\n", 13 | "$$\n", 14 | "# Appendix\n", 15 | "\n", 16 | "## Interactive Mode\n", 17 | "\n", 18 | "### Error Handling\n", 19 | "\n", 20 | "When an error occurs, the interpreter prints an error message and a stack trace. In interactive mode, it then returns to the primary prompt; when input came from a file, it exits with a nonzero exit status after printing the stack trace. (Exceptions handled by an except clause in a try statement are not errors in this context.) Some errors are unconditionally fatal and cause an exit with a nonzero exit; this applies to internal inconsistencies and some cases of running out of memory. All error messages are written to the standard error stream; normal output from executed commands is written to standard output.\n", 21 | "\n", 22 | "Typing the interrupt character (usually Control-C or Delete) to the primary or secondary prompt cancels the input and returns to the primary prompt.[1] Typing an interrupt while a command is executing raises the KeyboardInterrupt exception, which may be handled by a try statement.\n", 23 | "\n", 24 | "### Executable Python Scripts\n", 25 | "\n", 26 | "On BSD'ish Unix systems, Python scripts can be made directly executable, like shell scripts, by putting the line :" 27 | ] 28 | }, 29 | { 30 | "cell_type": "code", 31 | "execution_count": null, 32 | "metadata": {}, 33 | "outputs": [], 34 | "source": [ 35 | "#!/usr/bin/env python3.5" 36 | ] 37 | }, 38 | { 39 | "cell_type": "markdown", 40 | "metadata": {}, 41 | "source": [ 42 | "(assuming that the interpreter is on the user's PATH) at the beginning of the script and giving the file an executable mode. The `#!` must be the first two characters of the file. On some platforms, this first line must end with a Unix-style line ending (`'\\n'`), not a Windows (`'\\r\\n'`) line ending. Note that the hash, or pound, character, `'#'`, is used to start a comment in Python.\n", 43 | "\n", 44 | "The script can be given an executable mode, or permission, using the chmod command." 45 | ] 46 | }, 47 | { 48 | "cell_type": "code", 49 | "execution_count": null, 50 | "metadata": {}, 51 | "outputs": [], 52 | "source": [ 53 | "$ chmod +x myscript.py" 54 | ] 55 | }, 56 | { 57 | "cell_type": "markdown", 58 | "metadata": {}, 59 | "source": [ 60 | "On Windows systems, there is no notion of an \"executable mode\". The Python installer automatically associates `.py` files with `python.exe` so that a double-click on a Python file will run it as a script. The extension can also be `.pyw`, in that case, the console window that normally appears is suppressed.\n", 61 | "\n", 62 | "### The Interactive Startup File\n", 63 | "\n", 64 | "When you use Python interactively, it is frequently handy to have some standard commands executed every time the interpreter is started. You can do this by setting an environment variable named PYTHONSTARTUP to the name of a file containing your start-up commands. This is similar to the .profile feature of the Unix shells.\n", 65 | "\n", 66 | "This file is only read in interactive sessions, not when Python reads commands from a script, and not when /dev/tty is given as the explicit source of commands (which otherwise behaves like an interactive session). It is executed in the same namespace where interactive commands are executed, so that objects that it defines or imports can be used without qualification in the interactive session. You can also change the prompts `sys.ps1` and `sys.ps2` in this file.\n", 67 | "\n", 68 | "If you want to read an additional start-up file from the current directory, you can program this in the global start-up file using code like `if os.path.isfile('.pythonrc.py'): exec(open('.pythonrc.py').read())`. If you want to use the startup file in a script, you must do this explicitly in the script:" 69 | ] 70 | }, 71 | { 72 | "cell_type": "code", 73 | "execution_count": null, 74 | "metadata": {}, 75 | "outputs": [], 76 | "source": [ 77 | "import os\n", 78 | "filename = os.environ.get('PYTHONSTARTUP')\n", 79 | "if filename and os.path.isfile(filename):\n", 80 | " with open(filename) as fobj:\n", 81 | " startup_file = fobj.read()\n", 82 | " exec(startup_file)" 83 | ] 84 | }, 85 | { 86 | "cell_type": "markdown", 87 | "metadata": {}, 88 | "source": [ 89 | "### The Customization Modules\n", 90 | "\n", 91 | "Python provides two hooks to let you customize it: sitecustomize and usercustomize. To see how it works, you need first to find the location of your user site-packages directory. Start Python and run this code:" 92 | ] 93 | }, 94 | { 95 | "cell_type": "code", 96 | "execution_count": null, 97 | "metadata": {}, 98 | "outputs": [ 99 | { 100 | "data": { 101 | "text/plain": [ 102 | "'/home/user/.local/lib/python3.5/site-packages'" 103 | ] 104 | }, 105 | "execution_count": 1, 106 | "metadata": {}, 107 | "output_type": "execute_result" 108 | } 109 | ], 110 | "source": [ 111 | "import site\n", 112 | "site.getusersitepackages()" 113 | ] 114 | }, 115 | { 116 | "cell_type": "markdown", 117 | "metadata": {}, 118 | "source": [ 119 | "Now you can create a file named usercustomize.py in that directory and put anything you want in it. It will affect every invocation of Python, unless it is started with the -s option to disable the automatic import.\n", 120 | "\n", 121 | "sitecustomize works in the same way, but is typically created by an administrator of the computer in the global site-packages directory, and is imported before usercustomize. See the documentation of the site module for more details.\n", 122 | "\n", 123 | "**Footnotes**\n", 124 | "\n", 125 | "[1] A problem with the GNU Readline package may prevent this." 126 | ] 127 | } 128 | ], 129 | "metadata": {}, 130 | "nbformat": 4, 131 | "nbformat_minor": 2 132 | } 133 | -------------------------------------------------------------------------------- /Pyhton-Official-Tutorial-ipynb/appetite.rst.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "$$\n", 8 | "\\def\\CC{\\bf C}\n", 9 | "\\def\\QQ{\\bf Q}\n", 10 | "\\def\\RR{\\bf R}\n", 11 | "\\def\\ZZ{\\bf Z}\n", 12 | "\\def\\NN{\\bf N}\n", 13 | "$$\n", 14 | "# Whetting Your Appetite\n", 15 | "\n", 16 | "If you do much work on computers, eventually you find that there's some task you'd like to automate. For example, you may wish to perform a search-and-replace over a large number of text files, or rename and rearrange a bunch of photo files in a complicated way. Perhaps you'd like to write a small custom database, or a specialized GUI application, or a simple game.\n", 17 | "\n", 18 | "If you're a professional software developer, you may have to work with several C/C++/Java libraries but find the usual write/compile/test/re-compile cycle is too slow. Perhaps you're writing a test suite for such a library and find writing the testing code a tedious task. Or maybe you've written a program that could use an extension language, and you don't want to design and implement a whole new language for your application.\n", 19 | "\n", 20 | "Python is just the language for you.\n", 21 | "\n", 22 | "You could write a Unix shell script or Windows batch files for some of these tasks, but shell scripts are best at moving around files and changing text data, not well-suited for GUI applications or games. You could write a C/C++/Java program, but it can take a lot of development time to get even a first-draft program. Python is simpler to use, available on Windows, Mac OS X, and Unix operating systems, and will help you get the job done more quickly.\n", 23 | "\n", 24 | "Python is simple to use, but it is a real programming language, offering much more structure and support for large programs than shell scripts or batch files can offer. On the other hand, Python also offers much more error checking than C, and, being a *very-high-level language*, it has high-level data types built in, such as flexible arrays and dictionaries. Because of its more general data types Python is applicable to a much larger problem domain than Awk or even Perl, yet many things are at least as easy in Python as in those languages.\n", 25 | "\n", 26 | "Python allows you to split your program into modules that can be reused in other Python programs. It comes with a large collection of standard modules that you can use as the basis of your programs --- or as examples to start learning to program in Python. Some of these modules provide things like file I/O, system calls, sockets, and even interfaces to graphical user interface toolkits like Tk.\n", 27 | "\n", 28 | "Python is an interpreted language, which can save you considerable time during program development because no compilation and linking is necessary. The interpreter can be used interactively, which makes it easy to experiment with features of the language, to write throw-away programs, or to test functions during bottom-up program development. It is also a handy desk calculator.\n", 29 | "\n", 30 | "Python enables programs to be written compactly and readably. Programs written in Python are typically much shorter than equivalent C, C++, or Java programs, for several reasons:\n", 31 | "\n", 32 | "- the high-level data types allow you to express complex operations in a single statement;\n", 33 | "- statement grouping is done by indentation instead of beginning and ending brackets;\n", 34 | "- no variable or argument declarations are necessary.\n", 35 | "\n", 36 | "Python is *extensible*: if you know how to program in C it is easy to add a new built-in function or module to the interpreter, either to perform critical operations at maximum speed, or to link Python programs to libraries that may only be available in binary form (such as a vendor-specific graphics library). Once you are really hooked, you can link the Python interpreter into an application written in C and use it as an extension or command language for that application.\n", 37 | "\n", 38 | "By the way, the language is named after the BBC show \"Monty Python's Flying Circus\" and has nothing to do with reptiles. Making references to Monty Python skits in documentation is not only allowed, it is encouraged!\n", 39 | "\n", 40 | "Now that you are all excited about Python, you'll want to examine it in some more detail. Since the best way to learn a language is to use it, the tutorial invites you to play with the Python interpreter as you read.\n", 41 | "\n", 42 | "In the next chapter, the mechanics of using the interpreter are explained. This is rather mundane information, but essential for trying out the examples shown later.\n", 43 | "\n", 44 | "The rest of the tutorial introduces various features of the Python language and system through examples, beginning with simple expressions, statements and data types, through functions and modules, and finally touching upon advanced concepts like exceptions and user-defined classes." 45 | ] 46 | } 47 | ], 48 | "metadata": {}, 49 | "nbformat": 4, 50 | "nbformat_minor": 2 51 | } 52 | -------------------------------------------------------------------------------- /Pyhton-Official-Tutorial-ipynb/index.rst.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "$$\n", 8 | "\\def\\CC{\\bf C}\n", 9 | "\\def\\QQ{\\bf Q}\n", 10 | "\\def\\RR{\\bf R}\n", 11 | "\\def\\ZZ{\\bf Z}\n", 12 | "\\def\\NN{\\bf N}\n", 13 | "$$\n", 14 | "# The Python Tutorial\n", 15 | "\n", 16 | "Python is an easy to learn, powerful programming language. It has efficient high-level data structures and a simple but effective approach to object-oriented programming. Python's elegant syntax and dynamic typing, together with its interpreted nature, make it an ideal language for scripting and rapid application development in many areas on most platforms.\n", 17 | "\n", 18 | "The Python interpreter and the extensive standard library are freely available in source or binary form for all major platforms from the Python Web site, , and may be freely distributed. The same site also contains distributions of and pointers to many free third party Python modules, programs and tools, and additional documentation.\n", 19 | "\n", 20 | "The Python interpreter is easily extended with new functions and data types implemented in C or C++ (or other languages callable from C). Python is also suitable as an extension language for customizable applications.\n", 21 | "\n", 22 | "This tutorial introduces the reader informally to the basic concepts and features of the Python language and system. It helps to have a Python interpreter handy for hands-on experience, but all examples are self-contained, so the tutorial can be read off-line as well.\n", 23 | "\n", 24 | "For a description of standard objects and modules, see [library-index](library-index.ipynb). [reference-index](reference-index.ipynb) gives a more formal definition of the language. To write extensions in C or C++, read [extending-index](extending-index.ipynb) and [c-api-index](c-api-index.ipynb). There are also several books covering Python in depth.\n", 25 | "\n", 26 | "This tutorial does not attempt to be comprehensive and cover every single feature, or even every commonly used feature. Instead, it introduces many of Python's most noteworthy features, and will give you a good idea of the language's flavor and style. After reading it, you will be able to read and write Python modules and programs, and you will be ready to learn more about the various Python library modules described in [library-index](library-index.ipynb).\n", 27 | "\n", 28 | "The [glossary](glossary.ipynb) is also worth going through." 29 | ] 30 | } 31 | ], 32 | "metadata": {}, 33 | "nbformat": 4, 34 | "nbformat_minor": 2 35 | } 36 | -------------------------------------------------------------------------------- /Pyhton-Official-Tutorial-ipynb/interactive.rst.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "$$\n", 8 | "\\def\\CC{\\bf C}\n", 9 | "\\def\\QQ{\\bf Q}\n", 10 | "\\def\\RR{\\bf R}\n", 11 | "\\def\\ZZ{\\bf Z}\n", 12 | "\\def\\NN{\\bf N}\n", 13 | "$$\n", 14 | "# Interactive Input Editing and History Substitution\n", 15 | "\n", 16 | "Some versions of the Python interpreter support editing of the current input line and history substitution, similar to facilities found in the Korn shell and the GNU Bash shell. This is implemented using the [GNU Readline](https://tiswww.case.edu/php/chet/readline/rltop.html) library, which supports various styles of editing. This library has its own documentation which we won't duplicate here.\n", 17 | "\n", 18 | "## Tab Completion and History Editing\n", 19 | "\n", 20 | "Completion of variable and module names is [automatically enabled](rlcompleter-config.ipynb) at interpreter startup so that the Tab key invokes the completion function; it looks at Python statement names, the current local variables, and the available module names. For dotted expressions such as `string.a`, it will evaluate the expression up to the final `'.'` and then suggest completions from the attributes of the resulting object. Note that this may execute application-defined code if an object with a \\_\\_getattr\\_\\_ method is part of the expression. The default configuration also saves your history into a file named .python\\_history in your user directory. The history will be available again during the next interactive interpreter session.\n", 21 | "\n", 22 | "## Alternatives to the Interactive Interpreter\n", 23 | "\n", 24 | "This facility is an enormous step forward compared to earlier versions of the interpreter; however, some wishes are left: It would be nice if the proper indentation were suggested on continuation lines (the parser knows if an indent token is required next). The completion mechanism might use the interpreter's symbol table. A command to check (or even suggest) matching parentheses, quotes, etc., would also be useful.\n", 25 | "\n", 26 | "One alternative enhanced interactive interpreter that has been around for quite some time is [IPython](https://ipython.org/), which features tab completion, object exploration and advanced history management. It can also be thoroughly customized and embedded into other applications. Another similar enhanced interactive environment is [bpython](https://www.bpython-interpreter.org/)." 27 | ] 28 | } 29 | ], 30 | "metadata": {}, 31 | "nbformat": 4, 32 | "nbformat_minor": 2 33 | } 34 | -------------------------------------------------------------------------------- /Pyhton-Official-Tutorial-ipynb/interpreter.rst.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "$$\n", 8 | "\\def\\CC{\\bf C}\n", 9 | "\\def\\QQ{\\bf Q}\n", 10 | "\\def\\RR{\\bf R}\n", 11 | "\\def\\ZZ{\\bf Z}\n", 12 | "\\def\\NN{\\bf N}\n", 13 | "$$\n", 14 | "# Using the Python Interpreter\n", 15 | "\n", 16 | "## Invoking the Interpreter\n", 17 | "\n", 18 | "The Python interpreter is usually installed as /usr/local/bin/python3.8 on those machines where it is available; putting /usr/local/bin in your Unix shell's search path makes it possible to start it by typing the command:" 19 | ] 20 | }, 21 | { 22 | "cell_type": "code", 23 | "execution_count": null, 24 | "metadata": {}, 25 | "outputs": [], 26 | "source": [ 27 | "python3.8" 28 | ] 29 | }, 30 | { 31 | "cell_type": "markdown", 32 | "metadata": {}, 33 | "source": [ 34 | "to the shell.[1] Since the choice of the directory where the interpreter lives is an installation option, other places are possible; check with your local Python guru or system administrator. (E.g., /usr/local/python is a popular alternative location.)\n", 35 | "\n", 36 | "On Windows machines, the Python installation is usually placed in C:\\\\\\\\Python36, 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:" 37 | ] 38 | }, 39 | { 40 | "cell_type": "code", 41 | "execution_count": null, 42 | "metadata": {}, 43 | "outputs": [], 44 | "source": [ 45 | "set path=%path%;C:\\python36" 46 | ] 47 | }, 48 | { 49 | "cell_type": "markdown", 50 | "metadata": {}, 51 | "source": [ 52 | "Typing an end-of-file character (Control-D on Unix, Control-Z on Windows) at the primary prompt causes the interpreter to exit with a zero exit status. If that doesn't work, you can exit the interpreter by typing the following command: `quit()`.\n", 53 | "\n", 54 | "The interpreter's line-editing features include interactive editing, history substitution and code completion on systems that support readline. Perhaps the quickest check to see whether command line editing is supported is typing Control-P to the first Python prompt you get. If it beeps, you have command line editing; see Appendix [tut-interacting](tut-interacting.ipynb) for an introduction to the keys. If nothing appears to happen, or if `^P` is echoed, command line editing isn't available; you'll only be able to use backspace to remove characters from the current line.\n", 55 | "\n", 56 | "The interpreter operates somewhat like the Unix shell: when called with standard input connected to a tty device, it reads and executes commands interactively; when called with a file name argument or with a file as standard input, it reads and executes a *script* from that file.\n", 57 | "\n", 58 | "A second way of starting the interpreter is `python -c command [arg] ...`, which executes the statement(s) in *command*, analogous to the shell's -c option. Since Python statements often contain spaces or other characters that are special to the shell, it is usually advised to quote *command* in its entirety with single quotes.\n", 59 | "\n", 60 | "Some Python modules are also useful as scripts. These can be invoked using `python -m module [arg] ...`, which executes the source file for *module* as if you had spelled out its full name on the command line.\n", 61 | "\n", 62 | "When a script file is used, it is sometimes useful to be able to run the script and enter interactive mode afterwards. This can be done by passing -i before the script.\n", 63 | "\n", 64 | "All command line options are described in [using-on-general](using-on-general.ipynb).\n", 65 | "\n", 66 | "### Argument Passing\n", 67 | "\n", 68 | "When known to the interpreter, the script name and additional arguments thereafter are turned into a list of strings and assigned to the `argv` variable in the `sys` module. You can access this list by executing `import sys`. The length of the list is at least one; when no script and no arguments are given, `sys.argv[0]` is an empty string. When the script name is given as `'-'` (meaning standard input), `sys.argv[0]` is set to `'-'`. When -c *command* is used, `sys.argv[0]` is set to `'-c'`. When -m *module* is used, `sys.argv[0]` is set to the full name of the located module. Options found after -c *command* or -m *module* are not consumed by the Python interpreter's option processing but left in `sys.argv` for the command or module to handle.\n", 69 | "\n", 70 | "### Interactive Mode\n", 71 | "\n", 72 | "When commands are read from a tty, the interpreter is said to be in *interactive mode*. In this mode it prompts for the next command with the *primary prompt*, usually three greater-than signs (`>>>`); for continuation lines it prompts 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:" 73 | ] 74 | }, 75 | { 76 | "cell_type": "code", 77 | "execution_count": null, 78 | "metadata": {}, 79 | "outputs": [], 80 | "source": [ 81 | "$ python3.8\n", 82 | "Python 3.8 (default, Sep 16 2015, 09:25:04)\n", 83 | "[GCC 4.8.2] on linux\n", 84 | "Type \"help\", \"copyright\", \"credits\" or \"license\" for more information.\n", 85 | ">>>" 86 | ] 87 | }, 88 | { 89 | "cell_type": "markdown", 90 | "metadata": {}, 91 | "source": [ 92 | "Continuation lines are needed when entering a multi-line construct. As an example, take a look at this if statement:" 93 | ] 94 | }, 95 | { 96 | "cell_type": "code", 97 | "execution_count": null, 98 | "metadata": {}, 99 | "outputs": [ 100 | { 101 | "data": { 102 | "text/plain": [ 103 | "Be careful not to fall off!" 104 | ] 105 | }, 106 | "execution_count": 1, 107 | "metadata": {}, 108 | "output_type": "execute_result" 109 | } 110 | ], 111 | "source": [ 112 | "the_world_is_flat = True\n", 113 | "if the_world_is_flat:\n", 114 | " print(\"Be careful not to fall off!\")" 115 | ] 116 | }, 117 | { 118 | "cell_type": "markdown", 119 | "metadata": {}, 120 | "source": [ 121 | "For more on interactive mode, see [tut-interac](tut-interac.ipynb).\n", 122 | "\n", 123 | "## The Interpreter and Its Environment\n", 124 | "\n", 125 | "### Source Code Encoding\n", 126 | "\n", 127 | "By default, Python source files are treated as encoded in UTF-8. In that encoding, characters of most languages in the world can be used simultaneously in string literals, identifiers and comments --- although the standard library only uses ASCII characters for identifiers, a convention that any portable code should follow. To display all these characters properly, your editor must recognize that the file is UTF-8, and it must use a font that supports all the characters in the file.\n", 128 | "\n", 129 | "To declare an encoding other than the default one, a special comment line should be added as the *first* line of the file. The syntax is as follows:" 130 | ] 131 | }, 132 | { 133 | "cell_type": "code", 134 | "execution_count": null, 135 | "metadata": {}, 136 | "outputs": [], 137 | "source": [ 138 | "# -*- coding: encoding -*-" 139 | ] 140 | }, 141 | { 142 | "cell_type": "markdown", 143 | "metadata": {}, 144 | "source": [ 145 | "where *encoding* is one of the valid codecs supported by Python.\n", 146 | "\n", 147 | "For example, to declare that Windows-1252 encoding is to be used, the first line of your source code file should be:" 148 | ] 149 | }, 150 | { 151 | "cell_type": "code", 152 | "execution_count": null, 153 | "metadata": {}, 154 | "outputs": [], 155 | "source": [ 156 | "# -*- coding: cp1252 -*-" 157 | ] 158 | }, 159 | { 160 | "cell_type": "markdown", 161 | "metadata": {}, 162 | "source": [ 163 | "One exception to the *first line* rule is when the source code starts with a UNIX \"shebang\" line <tut-scripts>. In this case, the encoding declaration should be added as the second line of the file. For example:" 164 | ] 165 | }, 166 | { 167 | "cell_type": "code", 168 | "execution_count": null, 169 | "metadata": {}, 170 | "outputs": [], 171 | "source": [ 172 | "#!/usr/bin/env python3\n", 173 | "# -*- coding: cp1252 -*-" 174 | ] 175 | }, 176 | { 177 | "cell_type": "markdown", 178 | "metadata": {}, 179 | "source": [ 180 | "**Footnotes**\n", 181 | "\n", 182 | "[1] On Unix, the Python 3.x interpreter is by default not installed with the executable named `python`, so that it does not conflict with a simultaneously installed Python 2.x executable." 183 | ] 184 | } 185 | ], 186 | "metadata": {}, 187 | "nbformat": 4, 188 | "nbformat_minor": 2 189 | } 190 | -------------------------------------------------------------------------------- /Pyhton-Official-Tutorial-ipynb/venv.rst.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "$$\n", 8 | "\\def\\CC{\\bf C}\n", 9 | "\\def\\QQ{\\bf Q}\n", 10 | "\\def\\RR{\\bf R}\n", 11 | "\\def\\ZZ{\\bf Z}\n", 12 | "\\def\\NN{\\bf N}\n", 13 | "$$\n", 14 | "# Virtual Environments and Packages\n", 15 | "\n", 16 | "## Introduction\n", 17 | "\n", 18 | "Python applications will often use packages and modules that don't come as part of the standard library. Applications will sometimes need a specific version of a library, because the application may require that a particular bug has been fixed or the application may be written using an obsolete version of the library's interface.\n", 19 | "\n", 20 | "This means it may not be possible for one Python installation to meet the requirements of every application. If application A needs version 1.0 of a particular module but application B needs version 2.0, then the requirements are in conflict and installing either version 1.0 or 2.0 will leave one application unable to run.\n", 21 | "\n", 22 | "The solution for this problem is to create a virtual environment, a self-contained directory tree that contains a Python installation for a particular version of Python, plus a number of additional packages.\n", 23 | "\n", 24 | "Different applications can then use different virtual environments. To resolve the earlier example of conflicting requirements, application A can have its own virtual environment with version 1.0 installed while application B has another virtual environment with version 2.0. If application B requires a library be upgraded to version 3.0, this will not affect application A's environment.\n", 25 | "\n", 26 | "## Creating Virtual Environments\n", 27 | "\n", 28 | "The module used to create and manage virtual environments is called venv. venv will usually install the most recent version of Python that you have available. If you have multiple versions of Python on your system, you can select a specific Python version by running `python3` or whichever version you want.\n", 29 | "\n", 30 | "To create a virtual environment, decide upon a directory where you want to place it, and run the venv module as a script with the directory path:" 31 | ] 32 | }, 33 | { 34 | "cell_type": "code", 35 | "execution_count": null, 36 | "metadata": {}, 37 | "outputs": [], 38 | "source": [ 39 | "python3 -m venv tutorial-env" 40 | ] 41 | }, 42 | { 43 | "cell_type": "markdown", 44 | "metadata": {}, 45 | "source": [ 46 | "This will create the `tutorial-env` directory if it doesn't exist, and also create directories inside it containing a copy of the Python interpreter, the standard library, and various supporting files.\n", 47 | "\n", 48 | "Once you've created a virtual environment, you may activate it.\n", 49 | "\n", 50 | "On Windows, run:" 51 | ] 52 | }, 53 | { 54 | "cell_type": "code", 55 | "execution_count": null, 56 | "metadata": {}, 57 | "outputs": [], 58 | "source": [ 59 | "tutorial-env\\Scripts\\activate.bat" 60 | ] 61 | }, 62 | { 63 | "cell_type": "markdown", 64 | "metadata": {}, 65 | "source": [ 66 | "On Unix or MacOS, run:" 67 | ] 68 | }, 69 | { 70 | "cell_type": "code", 71 | "execution_count": null, 72 | "metadata": {}, 73 | "outputs": [], 74 | "source": [ 75 | "source tutorial-env/bin/activate" 76 | ] 77 | }, 78 | { 79 | "cell_type": "markdown", 80 | "metadata": {}, 81 | "source": [ 82 | "(This script is written for the bash shell. If you use the csh or fish shells, there are alternate `activate.csh` and `activate.fish` scripts you should use instead.)\n", 83 | "\n", 84 | "Activating the virtual environment will change your shell's prompt to show what virtual environment you're using, and modify the environment so that running `python` will get you that particular version and installation of Python. For example:" 85 | ] 86 | }, 87 | { 88 | "cell_type": "code", 89 | "execution_count": null, 90 | "metadata": {}, 91 | "outputs": [], 92 | "source": [ 93 | "$ source ~/envs/tutorial-env/bin/activate\n", 94 | "(tutorial-env) $ python\n", 95 | "Python 3.5.1 (default, May 6 2016, 10:59:36)\n", 96 | " ..." 97 | ] 98 | }, 99 | { 100 | "cell_type": "code", 101 | "execution_count": null, 102 | "metadata": {}, 103 | "outputs": [ 104 | { 105 | "data": { 106 | "text/plain": [ 107 | "['', '/usr/local/lib/python35.zip', ...,\n", 108 | "'~/envs/tutorial-env/lib/python3.5/site-packages']\n", 109 | ">>>" 110 | ] 111 | }, 112 | "execution_count": 1, 113 | "metadata": {}, 114 | "output_type": "execute_result" 115 | } 116 | ], 117 | "source": [ 118 | "import sys\n", 119 | "sys.path" 120 | ] 121 | }, 122 | { 123 | "cell_type": "markdown", 124 | "metadata": {}, 125 | "source": [ 126 | "## Managing Packages with pip\n", 127 | "\n", 128 | "You can install, upgrade, and remove packages using a program called pip. By default `pip` will install packages from the Python Package Index, <>. You can browse the Python Package Index by going to it in your web browser, or you can use `pip`'s limited search feature:" 129 | ] 130 | }, 131 | { 132 | "cell_type": "code", 133 | "execution_count": null, 134 | "metadata": {}, 135 | "outputs": [], 136 | "source": [ 137 | "(tutorial-env) $ pip search astronomy\n", 138 | "skyfield - Elegant astronomy for Python\n", 139 | "gary - Galactic astronomy and gravitational dynamics.\n", 140 | "novas - The United States Naval Observatory NOVAS astronomy library\n", 141 | "astroobs - Provides astronomy ephemeris to plan telescope observations\n", 142 | "PyAstronomy - A collection of astronomy related tools for Python." 143 | ] 144 | }, 145 | { 146 | "cell_type": "markdown", 147 | "metadata": {}, 148 | "source": [ 149 | "`pip` has a number of subcommands: \"search\", \"install\", \"uninstall\", \"freeze\", etc. (Consult the [installing-index](installing-index.ipynb) guide for complete documentation for `pip`.)\n", 150 | "\n", 151 | "You can install the latest version of a package by specifying a package's name:" 152 | ] 153 | }, 154 | { 155 | "cell_type": "code", 156 | "execution_count": null, 157 | "metadata": {}, 158 | "outputs": [], 159 | "source": [ 160 | "(tutorial-env) $ pip install novas\n", 161 | "Collecting novas\n", 162 | " Downloading novas-3.1.1.3.tar.gz (136kB)\n", 163 | "Installing collected packages: novas\n", 164 | " Running setup.py install for novas\n", 165 | "Successfully installed novas-3.1.1.3" 166 | ] 167 | }, 168 | { 169 | "cell_type": "markdown", 170 | "metadata": {}, 171 | "source": [ 172 | "You can also install a specific version of a package by giving the package name followed by `==` and the version number:" 173 | ] 174 | }, 175 | { 176 | "cell_type": "code", 177 | "execution_count": null, 178 | "metadata": {}, 179 | "outputs": [], 180 | "source": [ 181 | "(tutorial-env) $ pip install requests==2.6.0\n", 182 | "Collecting requests==2.6.0\n", 183 | " Using cached requests-2.6.0-py2.py3-none-any.whl\n", 184 | "Installing collected packages: requests\n", 185 | "Successfully installed requests-2.6.0" 186 | ] 187 | }, 188 | { 189 | "cell_type": "markdown", 190 | "metadata": {}, 191 | "source": [ 192 | "If you re-run this command, `pip` will notice that the requested version is already installed and do nothing. You can supply a different version number to get that version, or you can run `pip install --upgrade` to upgrade the package to the latest version:" 193 | ] 194 | }, 195 | { 196 | "cell_type": "code", 197 | "execution_count": null, 198 | "metadata": {}, 199 | "outputs": [], 200 | "source": [ 201 | "(tutorial-env) $ pip install --upgrade requests\n", 202 | "Collecting requests\n", 203 | "Installing collected packages: requests\n", 204 | " Found existing installation: requests 2.6.0\n", 205 | " Uninstalling requests-2.6.0:\n", 206 | " Successfully uninstalled requests-2.6.0\n", 207 | "Successfully installed requests-2.7.0" 208 | ] 209 | }, 210 | { 211 | "cell_type": "markdown", 212 | "metadata": {}, 213 | "source": [ 214 | "`pip uninstall` followed by one or more package names will remove the packages from the virtual environment.\n", 215 | "\n", 216 | "`pip show` will display information about a particular package:" 217 | ] 218 | }, 219 | { 220 | "cell_type": "code", 221 | "execution_count": null, 222 | "metadata": {}, 223 | "outputs": [], 224 | "source": [ 225 | "(tutorial-env) $ pip show requests\n", 226 | "---\n", 227 | "Metadata-Version: 2.0\n", 228 | "Name: requests\n", 229 | "Version: 2.7.0\n", 230 | "Summary: Python HTTP for Humans.\n", 231 | "Home-page: http://python-requests.org\n", 232 | "Author: Kenneth Reitz\n", 233 | "Author-email: me@kennethreitz.com\n", 234 | "License: Apache 2.0\n", 235 | "Location: /Users/akuchling/envs/tutorial-env/lib/python3.4/site-packages\n", 236 | "Requires:" 237 | ] 238 | }, 239 | { 240 | "cell_type": "markdown", 241 | "metadata": {}, 242 | "source": [ 243 | "`pip list` will display all of the packages installed in the virtual environment:" 244 | ] 245 | }, 246 | { 247 | "cell_type": "code", 248 | "execution_count": null, 249 | "metadata": {}, 250 | "outputs": [], 251 | "source": [ 252 | "(tutorial-env) $ pip list\n", 253 | "novas (3.1.1.3)\n", 254 | "numpy (1.9.2)\n", 255 | "pip (7.0.3)\n", 256 | "requests (2.7.0)\n", 257 | "setuptools (16.0)" 258 | ] 259 | }, 260 | { 261 | "cell_type": "markdown", 262 | "metadata": {}, 263 | "source": [ 264 | "`pip freeze` will produce a similar list of the installed packages, but the output uses the format that `pip install` expects. A common convention is to put this list in a `requirements.txt` file:" 265 | ] 266 | }, 267 | { 268 | "cell_type": "code", 269 | "execution_count": null, 270 | "metadata": {}, 271 | "outputs": [], 272 | "source": [ 273 | "(tutorial-env) $ pip freeze > requirements.txt\n", 274 | "(tutorial-env) $ cat requirements.txt\n", 275 | "novas==3.1.1.3\n", 276 | "numpy==1.9.2\n", 277 | "requests==2.7.0" 278 | ] 279 | }, 280 | { 281 | "cell_type": "markdown", 282 | "metadata": {}, 283 | "source": [ 284 | "The `requirements.txt` can then be committed to version control and shipped as part of an application. Users can then install all the necessary packages with `install -r` :" 285 | ] 286 | }, 287 | { 288 | "cell_type": "code", 289 | "execution_count": null, 290 | "metadata": {}, 291 | "outputs": [], 292 | "source": [ 293 | "(tutorial-env) $ pip install -r requirements.txt\n", 294 | "Collecting novas==3.1.1.3 (from -r requirements.txt (line 1))\n", 295 | " ...\n", 296 | "Collecting numpy==1.9.2 (from -r requirements.txt (line 2))\n", 297 | " ...\n", 298 | "Collecting requests==2.7.0 (from -r requirements.txt (line 3))\n", 299 | " ...\n", 300 | "Installing collected packages: novas, numpy, requests\n", 301 | " Running setup.py install for novas\n", 302 | "Successfully installed novas-3.1.1.3 numpy-1.9.2 requests-2.7.0" 303 | ] 304 | }, 305 | { 306 | "cell_type": "markdown", 307 | "metadata": {}, 308 | "source": [ 309 | "`pip` has many more options. Consult the [installing-index](installing-index.ipynb) guide for complete documentation for `pip`. When you've written a package and want to make it available on the Python Package Index, consult the [distributing-index](distributing-index.ipynb) guide." 310 | ] 311 | } 312 | ], 313 | "metadata": {}, 314 | "nbformat": 4, 315 | "nbformat_minor": 2 316 | } 317 | -------------------------------------------------------------------------------- /Pyhton-Official-Tutorial-ipynb/whatnow.rst.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "$$\n", 8 | "\\def\\CC{\\bf C}\n", 9 | "\\def\\QQ{\\bf Q}\n", 10 | "\\def\\RR{\\bf R}\n", 11 | "\\def\\ZZ{\\bf Z}\n", 12 | "\\def\\NN{\\bf N}\n", 13 | "$$\n", 14 | "# What Now?\n", 15 | "\n", 16 | "Reading this tutorial has probably reinforced your interest in using Python ---you should be eager to apply Python to solving your real-world problems. Where should you go to learn more?\n", 17 | "\n", 18 | "This tutorial is part of Python's documentation set. Some other documents in the set are:\n", 19 | "\n", 20 | "- [library-index](library-index.ipynb) :" 21 | ] 22 | }, 23 | { 24 | "cell_type": "markdown", 25 | "metadata": {}, 26 | "source": [ 27 | "\n", 28 | " You should browse through this manual, which gives complete (though terse) reference material about types, functions, and the modules in the standard library. The standard Python distribution includes a *lot* of additional code. There are modules to read Unix mailboxes, retrieve documents via HTTP, generate random numbers, parse command-line options, write CGI programs, compress data, and many other tasks. Skimming through the Library Reference will give you an idea of what's available.\n" 29 | ] 30 | }, 31 | { 32 | "cell_type": "markdown", 33 | "metadata": {}, 34 | "source": [ 35 | "- [installing-index](installing-index.ipynb) explains how to install additional modules written by other Python users.\n", 36 | "- [reference-index](reference-index.ipynb) : A detailed explanation of Python's syntax and semantics. It's heavy reading, but is useful as a complete guide to the language itself.\n", 37 | "\n", 38 | "More Python resources:\n", 39 | "\n", 40 | "- : The major Python Web site. It contains code, documentation, and pointers to Python-related pages around the Web. This Web site is mirrored in various places around the world, such as Europe, Japan, and Australia; a mirror may be faster than the main site, depending on your geographical location.\n", 41 | "- : Fast access to Python's documentation.\n", 42 | "- : The Python Package Index, previously also nicknamed the Cheese Shop, is an index of user-created Python modules that are available for download. Once you begin releasing code, you can register it here so that others can find it.\n", 43 | "- : The Python Cookbook is a sizable collection of code examples, larger modules, and useful scripts. Particularly notable contributions are collected in a book also titled Python Cookbook (O'Reilly & Associates, ISBN 0-596-00797-3.)\n", 44 | "- collects links to Python-related videos from conferences and user-group meetings.\n", 45 | "- : The Scientific Python project includes modules for fast array computations and manipulations plus a host of packages for such things as linear algebra, Fourier transforms, non-linear solvers, random number distributions, statistical analysis and the like.\n", 46 | "\n", 47 | "For Python-related questions and problem reports, you can post to the newsgroup comp.lang.python, or send them to the mailing list at . The newsgroup and mailing list are gatewayed, so messages posted to one will automatically be forwarded to the other. There are hundreds of postings a day, asking (and answering) questions, suggesting new features, and announcing new modules. Mailing list archives are available at .\n", 48 | "\n", 49 | "Before posting, be sure to check the list of [Frequently Asked Questions](faq-index.ipynb) (also called the FAQ). The FAQ answers many of the questions that come up again and again, and may already contain the solution for your problem." 50 | ] 51 | } 52 | ], 53 | "metadata": {}, 54 | "nbformat": 4, 55 | "nbformat_minor": 2 56 | } 57 | -------------------------------------------------------------------------------- /PythonOfficialTutorial.epub: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiaolai/the-python-tutorial-in-other-formats/49cf65d89a2b534fdea7b46ea60dedb51215a601/PythonOfficialTutorial.epub -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # The Python Tutorial epub/html/ipynb 2 | 3 | Original URI: 4 | 5 | > https://docs.python.org/3/tutorial/ 6 | 7 | Source from: 8 | 9 | > https://github.com/python/cpython/tree/master/Doc/tutorial 10 | 11 | html/epub converted by Sphinx 12 | 13 | > http://www.sphinx-doc.org 14 | 15 | ipynb converted by rst2ipynb 16 | 17 | > https://pypi.org/project/rst2ipynb/ --------------------------------------------------------------------------------