Only in cpython: build Only in cpython: config.log Only in cpython: config.status diff -ur cpython/Doc/tutorial/interactive.rst cpython-work/Doc/tutorial/interactive.rst --- cpython/Doc/tutorial/interactive.rst 2014-03-13 13:19:26.968392796 -0500 +++ cpython-work/Doc/tutorial/interactive.rst 2014-03-17 18:58:44.681074402 -0500 @@ -48,6 +48,166 @@ into other applications. Another similar enhanced interactive environment is bpython_. +.. _tut-argpassing: + +Argument Passing +---------------- + +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 +:option:`-c` *command* is used, ``sys.argv[0]`` is set to ``'-c'``. When +:option:`-m` *module* is used, ``sys.argv[0]`` is set to the full name of the +located module. Options found after :option:`-c` *command* or :option:`-m` +*module* are not consumed by the Python interpreter's option processing but +left in ``sys.argv`` for the command or module to handle. + +.. _tut-interactive: + +Interactive Mode +---------------- + +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:: + + $ python3.4 + Python 3.4 (default, Sep 24 2012, 09:25:04) + [GCC 4.6.3] on linux2 + Type "help", "copyright", "credits" or "license" for more information. + >>> + +.. XXX update for new releases + +Continuation lines are needed when entering a multi-line construct. As an +example, take a look at this :keyword:`if` statement:: + + >>> the_world_is_flat = 1 + >>> if the_world_is_flat: + ... print("Be careful not to fall off!") + ... + Be careful not to fall off! + +.. _tut-interp: + +The Interpreter and Its Environment +=================================== + + +.. _tut-error: + +Error Handling +-------------- + +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 :keyword:`except` clause in a :keyword:`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. + +Typing the interrupt character (usually Control-C or DEL) to the primary or +secondary prompt cancels the input and returns to the primary prompt. [#]_ +Typing an interrupt while a command is executing raises the +:exc:`KeyboardInterrupt` exception, which may be handled by a :keyword:`try` +statement. + +.. _tut-scripts: + +Executable Python Scripts +------------------------- + +On BSD'ish Unix systems, Python scripts can be made directly executable, like +shell scripts, by putting the line :: + + #! /usr/bin/env python3.4 + +(assuming that the interpreter is on the user's :envvar:`PATH`) at the beginning +of the script and giving the file an executable mode. The ``#!`` must be the +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. + +The script can be given an executable mode, or permission, using the +:program:`chmod` command:: + + $ chmod +x myscript.py + +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. + +.. _tut-startup: + +The Interactive Startup File +---------------------------- + +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 :envvar:`PYTHONSTARTUP` to the name of a +file containing your start-up commands. This is similar to the :file:`.profile` +feature of the Unix shells. + +.. XXX This should probably be dumped in an appendix, since most people + don't use Python interactively in non-trivial ways. + +This file is only read in interactive sessions, not when Python reads commands +from a script, and not when :file:`/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. + +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:: + + + import os + filename = os.environ.get('PYTHONSTARTUP') + if filename and os.path.isfile(filename): + exec(open(filename).read()) + +.. _tut-customize: + +The Customization Modules +------------------------- + +Python provides two hooks to let you customize it: :mod:`sitecustomize` and +:mod:`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: + + >>> import site + >>> site.getusersitepackages() + '/home/user/.local/lib/python3.2/site-packages' + +Now you can create a file named :file:`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 :option:`-s` option to disable the automatic import. + +:mod:`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 :mod:`usercustomize`. See the documentation of the :mod:`site` +module for more details. + +.. rubric:: Footnotes +.. [#] A problem with the GNU Readline package may prevent this. + .. _GNU Readline: http://tiswww.case.edu/php/chet/readline/rltop.html .. _IPython: http://ipython.scipy.org/ diff -ur cpython/Doc/tutorial/interpreter.rst cpython-work/Doc/tutorial/interpreter.rst --- cpython/Doc/tutorial/interpreter.rst 2014-03-13 13:19:26.968392796 -0500 +++ cpython-work/Doc/tutorial/interpreter.rst 2014-03-17 18:41:40.073106483 -0500 @@ -65,111 +65,6 @@ before the script. -.. _tut-argpassing: - -Argument Passing ----------------- - -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 -:option:`-c` *command* is used, ``sys.argv[0]`` is set to ``'-c'``. When -:option:`-m` *module* is used, ``sys.argv[0]`` is set to the full name of the -located module. Options found after :option:`-c` *command* or :option:`-m` -*module* are not consumed by the Python interpreter's option processing but -left in ``sys.argv`` for the command or module to handle. - - -.. _tut-interactive: - -Interactive Mode ----------------- - -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:: - - $ python3.4 - Python 3.4 (default, Sep 24 2012, 09:25:04) - [GCC 4.6.3] on linux2 - Type "help", "copyright", "credits" or "license" for more information. - >>> - -.. XXX update for new releases - -Continuation lines are needed when entering a multi-line construct. As an -example, take a look at this :keyword:`if` statement:: - - >>> the_world_is_flat = 1 - >>> if the_world_is_flat: - ... print("Be careful not to fall off!") - ... - Be careful not to fall off! - - -.. _tut-interp: - -The Interpreter and Its Environment -=================================== - - -.. _tut-error: - -Error Handling --------------- - -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 :keyword:`except` clause in a :keyword:`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. - -Typing the interrupt character (usually Control-C or DEL) to the primary or -secondary prompt cancels the input and returns to the primary prompt. [#]_ -Typing an interrupt while a command is executing raises the -:exc:`KeyboardInterrupt` exception, which may be handled by a :keyword:`try` -statement. - - -.. _tut-scripts: - -Executable Python Scripts -------------------------- - -On BSD'ish Unix systems, Python scripts can be made directly executable, like -shell scripts, by putting the line :: - - #! /usr/bin/env python3.4 - -(assuming that the interpreter is on the user's :envvar:`PATH`) at the beginning -of the script and giving the file an executable mode. The ``#!`` must be the -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. - -The script can be given an executable mode, or permission, using the -:program:`chmod` command:: - - $ chmod +x myscript.py - -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. - - .. _tut-source-encoding: Source Code Encoding @@ -203,67 +98,8 @@ within the file. -.. _tut-startup: - -The Interactive Startup File ----------------------------- - -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 :envvar:`PYTHONSTARTUP` to the name of a -file containing your start-up commands. This is similar to the :file:`.profile` -feature of the Unix shells. - -.. XXX This should probably be dumped in an appendix, since most people - don't use Python interactively in non-trivial ways. - -This file is only read in interactive sessions, not when Python reads commands -from a script, and not when :file:`/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. - -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:: - - import os - filename = os.environ.get('PYTHONSTARTUP') - if filename and os.path.isfile(filename): - exec(open(filename).read()) - - -.. _tut-customize: - -The Customization Modules -------------------------- - -Python provides two hooks to let you customize it: :mod:`sitecustomize` and -:mod:`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: - - >>> import site - >>> site.getusersitepackages() - '/home/user/.local/lib/python3.2/site-packages' - -Now you can create a file named :file:`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 :option:`-s` option to disable the automatic import. - -:mod:`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 :mod:`usercustomize`. See the documentation of the :mod:`site` -module for more details. - - .. rubric:: Footnotes .. [#] 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. - -.. [#] A problem with the GNU Readline package may prevent this. Binary files cpython/.hg/dirstate and cpython-work/.hg/dirstate differ diff -ur cpython/.hg/hgrc cpython-work/.hg/hgrc --- cpython/.hg/hgrc 2014-03-13 13:19:26.528392810 -0500 +++ cpython-work/.hg/hgrc 2014-03-17 15:24:55.818299076 -0500 @@ -1,2 +1,2 @@ [paths] -default = http://hg.python.org/cpython +default = /home/jamayla/cpython Only in cpython/.hg/store: undo Only in cpython/.hg: undo.bookmarks Only in cpython/.hg: undo.branch Only in cpython/.hg: undo.desc Only in cpython/.hg: undo.dirstate Only in cpython/Lib/asyncio: __pycache__ Only in cpython/Lib/collections: __pycache__ Only in cpython/Lib/concurrent/futures: __pycache__ Only in cpython/Lib/concurrent: __pycache__ Only in cpython/Lib/ctypes/macholib: __pycache__ Only in cpython/Lib/ctypes: __pycache__ Only in cpython/Lib/ctypes/test: __pycache__ Only in cpython/Lib/dbm: __pycache__ Only in cpython/Lib/distutils/command: __pycache__ Only in cpython/Lib/distutils: __pycache__ Only in cpython/Lib/distutils/tests: __pycache__ Only in cpython/Lib/email/mime: __pycache__ Only in cpython/Lib/email: __pycache__ Only in cpython/Lib/encodings: __pycache__ Only in cpython/Lib/ensurepip: __pycache__ Only in cpython/Lib/html: __pycache__ Only in cpython/Lib/http: __pycache__ Only in cpython/Lib/idlelib: __pycache__ Only in cpython/Lib/importlib: __pycache__ Only in cpython/Lib/json: __pycache__ Only in cpython/Lib/lib2to3/fixes: __pycache__ Only in cpython/Lib/lib2to3: Grammar3.4.0.candidate.1.pickle Only in cpython/Lib/lib2to3: PatternGrammar3.4.0.candidate.1.pickle Only in cpython/Lib/lib2to3/pgen2: __pycache__ Only in cpython/Lib/lib2to3: __pycache__ Only in cpython/Lib/lib2to3/tests/data/fixers/myfixes: __pycache__ Only in cpython/Lib/lib2to3/tests/data/fixers: __pycache__ Only in cpython/Lib/lib2to3/tests: __pycache__ Only in cpython/Lib/logging: __pycache__ Only in cpython/Lib/msilib: __pycache__ Only in cpython/Lib/multiprocessing/dummy: __pycache__ Only in cpython/Lib/multiprocessing: __pycache__ Only in cpython/Lib/plat-linux: __pycache__ Only in cpython/Lib: __pycache__ Only in cpython/Lib/pydoc_data: __pycache__ Only in cpython/Lib/test/encoded_modules: __pycache__ Only in cpython/Lib/test/leakers: __pycache__ Only in cpython/Lib/test/namespace_pkgs/both_portions/foo: __pycache__ Only in cpython/Lib/test/namespace_pkgs/module_and_namespace_package: __pycache__ Only in cpython/Lib/test/namespace_pkgs/not_a_namespace_pkg/foo: __pycache__ Only in cpython/Lib/test/namespace_pkgs/portion1/foo: __pycache__ Only in cpython/Lib/test/namespace_pkgs/portion2/foo: __pycache__ Only in cpython/Lib/test/namespace_pkgs/project1/parent/child: __pycache__ Only in cpython/Lib/test/namespace_pkgs/project2/parent/child: __pycache__ Only in cpython/Lib/test/namespace_pkgs/project3/parent/child: __pycache__ Only in cpython/Lib/test: __pycache__ Only in cpython/Lib/test/support: __pycache__ Only in cpython/Lib/test/test_asyncio: __pycache__ Only in cpython/Lib/test/test_email: __pycache__ Only in cpython/Lib/test/test_importlib/builtin: __pycache__ Only in cpython/Lib/test/test_importlib/extension: __pycache__ Only in cpython/Lib/test/test_importlib/frozen: __pycache__ Only in cpython/Lib/test/test_importlib/import_: __pycache__ Only in cpython/Lib/test/test_importlib: __pycache__ Only in cpython/Lib/test/test_importlib/source: __pycache__ Only in cpython/Lib/test/test_json: __pycache__ Only in cpython/Lib/test/tracedmodules: __pycache__ Only in cpython/Lib/tkinter: __pycache__ Only in cpython/Lib/unittest: __pycache__ Only in cpython/Lib/unittest/test: __pycache__ Only in cpython/Lib/unittest/test/testmock: __pycache__ Only in cpython/Lib/urllib: __pycache__ Only in cpython/Lib/venv: __pycache__ Only in cpython/Lib/wsgiref: __pycache__ Only in cpython/Lib/xml/dom: __pycache__ Only in cpython/Lib/xml/etree: __pycache__ Only in cpython/Lib/xml/parsers: __pycache__ Only in cpython/Lib/xml: __pycache__ Only in cpython/Lib/xml/sax: __pycache__ Only in cpython/Lib/xmlrpc: __pycache__ Only in cpython: libpython3.4dm.a Only in cpython: Makefile Only in cpython: Makefile.pre Only in cpython/Misc: python-config.sh Only in cpython/Misc: python.pc Only in cpython/Modules: atexitmodule.o Only in cpython/Modules: bufferedio.o Only in cpython/Modules: bytesio.o Only in cpython/Modules: _codecsmodule.o Only in cpython/Modules: _collectionsmodule.o Only in cpython/Modules: config.c Only in cpython/Modules: config.o Only in cpython/Modules: errnomodule.o Only in cpython/Modules: faulthandler.o Only in cpython/Modules: fileio.o Only in cpython/Modules: _functoolsmodule.o Only in cpython/Modules: gcmodule.o Only in cpython/Modules: getbuildinfo.o Only in cpython/Modules: getpath.o Only in cpython/Modules: hashtable.o Only in cpython/Modules: iobase.o Only in cpython/Modules: _iomodule.o Only in cpython/Modules: itertoolsmodule.o Only in cpython/Modules: ld_so_aix Only in cpython/Modules: _localemodule.o Only in cpython/Modules: main.o Only in cpython/Modules: _operator.o Only in cpython/Modules: posixmodule.o Only in cpython/Modules: pwdmodule.o Only in cpython/Modules: python.o Only in cpython/Modules: Setup Only in cpython/Modules: Setup.config Only in cpython/Modules: Setup.local Only in cpython/Modules: signalmodule.o Only in cpython/Modules: _sre.o Only in cpython/Modules: _stat.o Only in cpython/Modules: stringio.o Only in cpython/Modules: symtablemodule.o Only in cpython/Modules: _testembed Only in cpython/Modules: _testembed.o Only in cpython/Modules: textio.o Only in cpython/Modules: _threadmodule.o Only in cpython/Modules: _tracemalloc.o Only in cpython/Modules: _weakref.o Only in cpython/Modules: xxsubtype.o Only in cpython/Modules: zipimport.o Only in cpython/Objects: abstract.o Only in cpython/Objects: accu.o Only in cpython/Objects: boolobject.o Only in cpython/Objects: bytearrayobject.o Only in cpython/Objects: bytes_methods.o Only in cpython/Objects: bytesobject.o Only in cpython/Objects: capsule.o Only in cpython/Objects: cellobject.o Only in cpython/Objects: classobject.o Only in cpython/Objects: codeobject.o Only in cpython/Objects: complexobject.o Only in cpython/Objects: descrobject.o Only in cpython/Objects: dictobject.o Only in cpython/Objects: enumobject.o Only in cpython/Objects: exceptions.o Only in cpython/Objects: fileobject.o Only in cpython/Objects: floatobject.o Only in cpython/Objects: frameobject.o Only in cpython/Objects: funcobject.o Only in cpython/Objects: genobject.o Only in cpython/Objects: iterobject.o Only in cpython/Objects: listobject.o Only in cpython/Objects: longobject.o Only in cpython/Objects: memoryobject.o Only in cpython/Objects: methodobject.o Only in cpython/Objects: moduleobject.o Only in cpython/Objects: namespaceobject.o Only in cpython/Objects: object.o Only in cpython/Objects: obmalloc.o Only in cpython/Objects: rangeobject.o Only in cpython/Objects: setobject.o Only in cpython/Objects: sliceobject.o Only in cpython/Objects: structseq.o Only in cpython/Objects: tupleobject.o Only in cpython/Objects: typeobject.o Only in cpython/Objects: unicodectype.o Only in cpython/Objects: unicodeobject.o Only in cpython/Objects: weakrefobject.o Only in cpython/Parser: acceler.o Only in cpython/Parser: bitset.o Only in cpython/Parser: firstsets.o Only in cpython/Parser: grammar1.o Only in cpython/Parser: grammar.o Only in cpython/Parser: listnode.o Only in cpython/Parser: metagrammar.o Only in cpython/Parser: myreadline.o Only in cpython/Parser: node.o Only in cpython/Parser: parser.o Only in cpython/Parser: parsetok.o Only in cpython/Parser: parsetok_pgen.o Only in cpython/Parser: pgen Only in cpython/Parser: pgenmain.o Only in cpython/Parser: pgen.o Only in cpython/Parser: printgrammar.o Only in cpython/Parser: __pycache__ Only in cpython/Parser: tokenizer.o Only in cpython/Parser: tokenizer_pgen.o Only in cpython: pybuilddir.txt Only in cpython: pyconfig.h Only in cpython: python Only in cpython/Python: asdl.o Only in cpython/Python: ast.o Only in cpython/Python: bltinmodule.o Only in cpython/Python: ceval.o Only in cpython/Python: codecs.o Only in cpython/Python: compile.o Only in cpython/Python: dtoa.o Only in cpython/Python: dynamic_annotations.o Only in cpython/Python: dynload_shlib.o Only in cpython/Python: errors.o Only in cpython/Python: fileutils.o Only in cpython/Python: formatter_unicode.o Only in cpython/Python: frozenmain.o Only in cpython/Python: frozen.o Only in cpython/Python: future.o Only in cpython/Python: getargs.o Only in cpython/Python: getcompiler.o Only in cpython/Python: getcopyright.o Only in cpython/Python: getopt.o Only in cpython/Python: getplatform.o Only in cpython/Python: getversion.o Only in cpython/Python: graminit.o Only in cpython/Python: importdl.o Only in cpython/Python: import.o Only in cpython/Python: marshal.o Only in cpython/Python: modsupport.o Only in cpython/Python: mysnprintf.o Only in cpython/Python: mystrtoul.o Only in cpython/Python: peephole.o Only in cpython/Python: pyarena.o Only in cpython/Python: pyctype.o Only in cpython/Python: pyfpe.o Only in cpython/Python: pyhash.o Only in cpython/Python: pymath.o Only in cpython/Python: pystate.o Only in cpython/Python: pystrcmp.o Only in cpython/Python: pystrtod.o Only in cpython/Python: Python-ast.o Only in cpython/Python: pythonrun.o Only in cpython/Python: pytime.o Only in cpython/Python: random.o Only in cpython/Python: structmember.o Only in cpython/Python: symtable.o Only in cpython/Python: sysmodule.o Only in cpython/Python: thread.o Only in cpython/Python: traceback.o Only in cpython/Python: _warnings.o Only in cpython: python-config Only in cpython: python-config.py Only in cpython: python-gdb.py Only in cpython/Tools/parser: __pycache__ Only in cpython/Tools/scripts: __pycache__