├── .gitattributes ├── .gitignore ├── Chapter01 ├── activate_venv.py ├── binary_wheel.py ├── cd_project.py ├── constraints_txt.py ├── create_venv.py ├── cwd.py ├── cxfreeze_install.py ├── cxfreeze_setup.py ├── cython_setup.py ├── dice_roll_results.py ├── dice_roller.py ├── dice_roller_tests.py ├── first_funct.py ├── first_module.py ├── git_local_file.py ├── git_tag.py ├── import_dice_roller.py ├── import_math.py ├── inplace_build.py ├── manifest_template.py ├── math_import_all.py ├── math_sin.py ├── nested_functions.py ├── new_temp_dir.py ├── nuitka_module.py ├── nuitka_recursive.py ├── nuitka_setup.py ├── package_tree.py ├── pip_force_install.py ├── pip_install.py ├── pip_install_latest.py ├── pip_install_minimum.py ├── pip_install_specific_version.py ├── pip_local_wheel.py ├── pip_outdated.py ├── pip_search.py ├── pip_show.py ├── pip_tmp_dir.py ├── pip_wheel.py ├── pipenv_install.py ├── pipenv_run.py ├── pipenv_shell.py ├── pipfile.py ├── pipfile_lock.py ├── print_enum.py ├── print_funct.py ├── print_mult_args.py ├── project_hash.py ├── py2exe_setup.py ├── pyinstaller.py ├── randint.py ├── randrange.py ├── rel_imports.py ├── requirements_txt.py ├── second_funct.py ├── second_module.py ├── sin_no_import.py ├── tar_file.py ├── temp_dir.py ├── third_module.py ├── twine_error.py ├── twine_registration.py ├── twine_upload.py ├── universal_wheel.py ├── untar_file.py ├── versioning.py └── wheel_create.py ├── Chapter02 ├── apt_install_package.py ├── bpython_requirements.py ├── bypthon_clone.py ├── bypthon_install.py ├── call_module.py ├── command_opts.py ├── dreampie_clone.py ├── exec_script.py ├── interactive_mode.py ├── ipython_prompt.py ├── ironpython_install.py ├── jupyter_install.py ├── jython_console.py ├── jython_install.py ├── make_html.py ├── micropython.py ├── os_environ.py ├── print_path.py ├── read_startup.py ├── run_command.py ├── run_ipython.py ├── run_script.py ├── specify_version.py ├── stackless_install.py ├── startup_script.py ├── windows_install.py ├── winpy_error.py └── winpy_version.py ├── Chapter03 ├── add_attributes.py ├── call_dec.py ├── call_funct.py ├── cat_class.py ├── cat_instance.py ├── circle_call.py ├── class_method.py ├── dec_funct.py ├── dec_wrapper.py ├── decorated_funct.py ├── decorator.py ├── decorator_appearance.py ├── decorator_args.py ├── decorator_value.py ├── def_memoize.py ├── define_decorator.py ├── define_login.py ├── final_code.py ├── funct_as_arg.py ├── funct_names.py ├── funct_nesting.py ├── funct_param.py ├── funct_scope.py ├── function_enforcement.py ├── generic_funct.py ├── import_flask.py ├── import_wraps.py ├── inventory_dec.py ├── long_flask_program.py ├── main_funct.py ├── memoize_dec.py ├── memoize_funct.py ├── return_funct.py ├── run_memoize.py ├── static_method.py ├── time_dec.py ├── time_decorator_creation.py └── whole_program.py ├── Chapter04 ├── adult_list_comp.py ├── age_groups.py ├── bags_vs_counter.py ├── book_catalog.py ├── chainmap_builtins.py ├── chainmap_combined.py ├── chainmap_import.py ├── chainmap_nested_context.py ├── class_adult.py ├── count_elements.py ├── counter_del.py ├── counter_import.py ├── counter_math.py ├── counter_most_common.py ├── counter_ops.py ├── counter_shortcuts.py ├── counter_subtract.py ├── counter_text_map.py ├── counter_zero.py ├── deep_chainmap.py ├── defauldict_items.py ├── defaultdict_age_groups.py ├── defaultdict_counting.py ├── defaultdict_error.py ├── defaultdict_import.py ├── defaultdict_lambda.py ├── defaultdict_set.py ├── defaultdict_setdefault.py ├── deque_add_items.py ├── deque_avg.py ├── deque_clear.py ├── deque_delete.py ├── deque_extend.py ├── deque_extendleft.py ├── deque_in.py ├── deque_instance.py ├── deque_iter.py ├── deque_list.py ├── deque_peek.py ├── deque_pop.py ├── deque_repr.py ├── deque_reverse.py ├── deque_reverse2.py ├── deque_rotate.py ├── deque_tail.py ├── dict_to_namedtuple.py ├── diff_sort.py ├── employee_record_tuple.py ├── ext_collections_bag.py ├── ext_collections_bag_compare.py ├── ext_collections_bag_compare2.py ├── ext_collections_bijection.py ├── ext_collections_rangemap.py ├── ext_collections_setlist.py ├── file_open.py ├── getattr.py ├── import_csv.py ├── import_deque.py ├── import_sqlite.py ├── list_of_lists.py ├── list_sort.py ├── namedtuple_account.py ├── namedtuple_asdict.py ├── namedtuple_book.py ├── namedtuple_create.py ├── namedtuple_fields.py ├── namedtuple_indexed.py ├── namedtuple_instance.py ├── namedtuple_make.py ├── namedtuple_names.py ├── namedtuple_replace.py ├── namedtuple_repr.py ├── namedtuple_sales.py ├── namedtuple_subclass.py ├── namedtuple_unpack.py ├── ordereddict_counter.py ├── ordereddict_keys.py ├── ordereddict_move.py ├── ordereddict_reduce.py ├── ordereddict_rem_reduce.py ├── ordereddict_store_keys.py ├── ordereddict_use.py ├── receipts_make.py ├── sales_csv.py ├── store_fields.py ├── student_grades.py ├── userdict_import.py ├── userlist_import.py └── userstring_import.py ├── Chapter05 ├── asyncio_concurrent.py ├── asyncio_multi_jobs.py ├── coroutine_decorator.py ├── coroutine_func.py ├── coroutine_input.py ├── coroutine_instance.py ├── coroutine_next.py ├── define_child.py ├── define_parent.py ├── gen_comprehension.py ├── gen_comprehension_loop.py ├── generator_example.py ├── list_comprehension.py ├── multi_process_retrieval.py ├── multi_thread_retrieval.py ├── os_import.py ├── reverse_seq.py ├── single_thread.py └── time_funct.py ├── Chapter07 ├── add_funct.py ├── beer_loop.py ├── change_variable.py ├── great_circle.py ├── loop_funct.c ├── loop_funct.py ├── time.py └── time2.py ├── Chapter08 ├── audit_hook.py ├── audit_hook_api.py ├── callback_collect.txt ├── collect_gens.txt ├── gc_collect.txt ├── gc_get_mode.txt ├── gc_malloc.txt ├── gc_set_mode.txt ├── gc_thread.txt ├── hook_handler.py ├── hook_handler_api.py ├── implicit_gc.txt ├── interpreter_data_share.txt ├── interpreter_exception.txt ├── interpreter_isolate.txt ├── interpreter_marshal.txt ├── interpreter_pickle.txt ├── interpreter_prepopulate.txt ├── interpreter_spawn_thread.txt ├── interpreter_synch.txt ├── launch_malware.py ├── lock_collect.txt ├── sched_gc.txt ├── subinterpreter_module.txt ├── subinterpreter_pool.txt └── subinterpreter_script.txt ├── Chapter09 ├── alert.js ├── docstring_example.py ├── doctest.py ├── jsf.js └── perl_interactive.pl ├── LICENSE └── README.md /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | 7 | # Standard to msysgit 8 | *.doc diff=astextplain 9 | *.DOC diff=astextplain 10 | *.docx diff=astextplain 11 | *.DOCX diff=astextplain 12 | *.dot diff=astextplain 13 | *.DOT diff=astextplain 14 | *.pdf diff=astextplain 15 | *.PDF diff=astextplain 16 | *.rtf diff=astextplain 17 | *.RTF diff=astextplain 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Windows image file caches 2 | Thumbs.db 3 | ehthumbs.db 4 | 5 | # Folder config file 6 | Desktop.ini 7 | 8 | # Recycle Bin used on file shares 9 | $RECYCLE.BIN/ 10 | 11 | # Windows Installer files 12 | *.cab 13 | *.msi 14 | *.msm 15 | *.msp 16 | 17 | # Windows shortcuts 18 | *.lnk 19 | 20 | # ========================= 21 | # Operating System Files 22 | # ========================= 23 | 24 | # OSX 25 | # ========================= 26 | 27 | .DS_Store 28 | .AppleDouble 29 | .LSOverride 30 | 31 | # Thumbnails 32 | ._* 33 | 34 | # Files that might appear in the root of a volume 35 | .DocumentRevisions-V100 36 | .fseventsd 37 | .Spotlight-V100 38 | .TemporaryItems 39 | .Trashes 40 | .VolumeIcon.icns 41 | 42 | # Directories potentially created on remote AFP share 43 | .AppleDB 44 | .AppleDesktop 45 | Network Trash Folder 46 | Temporary Items 47 | .apdisk 48 | -------------------------------------------------------------------------------- /Chapter01/activate_venv.py: -------------------------------------------------------------------------------- 1 | source /bin/activate 2 | 3 | -------------------------------------------------------------------------------- /Chapter01/binary_wheel.py: -------------------------------------------------------------------------------- 1 | python setup.py bdist_wheel 2 | 3 | -------------------------------------------------------------------------------- /Chapter01/cd_project.py: -------------------------------------------------------------------------------- 1 | >>> cd 2 | -------------------------------------------------------------------------------- /Chapter01/constraints_txt.py: -------------------------------------------------------------------------------- 1 | # math / science / graph stuff 2 | bokeh==0.11.1 3 | numpy==1.10.4 4 | pandas==0.17.1 5 | scipy==0.17.0 6 | openpyxl==2.3.3 7 | patsy==0.4.1 8 | matplotlib==1.5.1 9 | ggplot==0.6.8 10 | Theano==0.7.0 11 | seaborn==0.7.0 12 | scikit-learn==0.17 13 | 14 | pymldb==0.8.1 15 | pivottablejs==0.1.0 16 | 17 | # Progress bar 18 | tqdm==4.11.0 19 | 20 | # notebook and friends 21 | ipython==5.1.0 22 | jupyter==1.0.0 23 | jupyter-client==4.4.0 24 | jupyter-console==5.0.0 25 | jupyter-core==4.2.1 26 | 27 | # validator 28 | uWSGI==2.0.12 29 | pycrypto==2.6.1 30 | 31 | tornado==4.4.2 32 | 33 | ## The following requirements were added by pip freeze: 34 | backports-abc==0.5 35 | backports.shutil-get-terminal-size==1.0.0 36 | backports.ssl-match-hostname==3.5.0.1 37 | bleach==1.5.0 38 | 39 | ***further files truncated*** 40 | -------------------------------------------------------------------------------- /Chapter01/create_venv.py: -------------------------------------------------------------------------------- 1 | >>> python3 -m venv 2 | 3 | -------------------------------------------------------------------------------- /Chapter01/cwd.py: -------------------------------------------------------------------------------- 1 | $ cwd = `pwd` 2 | 3 | -------------------------------------------------------------------------------- /Chapter01/cxfreeze_install.py: -------------------------------------------------------------------------------- 1 | cxfreeze .py --target-dir= 2 | 3 | -------------------------------------------------------------------------------- /Chapter01/cxfreeze_setup.py: -------------------------------------------------------------------------------- 1 | import sys 2 | from cx_Freeze import setup, Executable 3 | 4 | # Dependencies are automatically detected, but it might need fine tuning. 5 | build_exe_options = {"packages": ["os"], "excludes": ["tkinter"]} 6 | 7 | # GUI applications require a different base on Windows (the default is for a 8 | # console application). 9 | base = None 10 | if sys.platform == "win32": 11 | base = "Win32GUI" 12 | 13 | setup( name = "guifoo", 14 | version = "0.1", 15 | description = "My GUI application!", 16 | options = {"build_exe": build_exe_options}, 17 | executables = [Executable("guifoo.py", base=base)]) 18 | -------------------------------------------------------------------------------- /Chapter01/cython_setup.py: -------------------------------------------------------------------------------- 1 | from distutils.core import setup 2 | from Cython.Build import cythonize 3 | 4 | setup( 5 | ext_modules = cythonize("helloworld.pyx") 6 | ) 7 | -------------------------------------------------------------------------------- /Chapter01/dice_roll_results.py: -------------------------------------------------------------------------------- 1 | $ python3 random_dice.py 1 2 | 2 3 | $ python3 random_dice.py 2 4 | 10 5 | $ python3 random_dice.py 3 6 | 63 7 | $ python3 random_dice.py 4 8 | 2 9 | $ python3 random_dice.py 5 10 | 5 11 | $ python3 random_dice.py 6 12 | 6 13 | $ python3 random_dice.py 7 14 | 17 15 | $ python3 random_dice.py 8 16 | Shouldn't be here. Invalid choice 17 | -------------------------------------------------------------------------------- /Chapter01/dice_roller.py: -------------------------------------------------------------------------------- 1 | import random 2 | def randomNumGen(choice): 3 | if choice == 1: #d6 roll 4 | die = random.randint(1, 6) 5 | elif choice == 2: #d10 roll 6 | die = random.randint(1, 10) 7 | elif choice == 3: #d100 roll 8 | die = random.randint(1, 100) 9 | elif choice == 4: #d4 roll 10 | die = random.randint(1, 4) 11 | elif choice == 5: #d8 roll 12 | die = random.randint(1, 8) 13 | elif choice == 6: #d12 roll 14 | die = random.randint(1, 12) 15 | elif choice == 7: #d20 roll 16 | die = random.randint(1, 20) 17 | else: #simple error message 18 | return "Shouldn't be here. Invalid choice" 19 | return die 20 | if __name__ == "__main__": 21 | import sys 22 | print(randomNumGen(int(sys.argv[1]))) 23 | -------------------------------------------------------------------------------- /Chapter01/dice_roller_tests.py: -------------------------------------------------------------------------------- 1 | import random #randint 2 | def randomNumGen(choice): 3 | """Get a random number to simulate a d6, d10, or d100 roll.""" 4 | 5 | if choice == 1: #d6 roll 6 | die = random.randint(1, 6) 7 | elif choice == 2: #d10 roll 8 | die = random.randint(1, 10) 9 | elif choice == 3: #d100 roll 10 | die = random.randint(1, 100) 11 | elif choice == 4: #d4 roll 12 | die = random.randint(1, 4) 13 | elif choice == 5: #d8 roll 14 | die = random.randint(1, 8) 15 | elif choice == 6: #d12 roll 16 | die = random.randint(1, 12) 17 | elif choice == 7: #d20 roll 18 | die = random.randint(1, 20) 19 | else: #simple error message 20 | return "Shouldn't be here. Invalid choice" 21 | return die 22 | def multiDie(dice_number, die_type): 23 | """Add die rolls together, e.g. 2d6, 4d10, etc.""" 24 | 25 | #---Initialize variables 26 | final_roll = 0 27 | val = 0 28 | 29 | while val < dice_number: 30 | final_roll += randomNumGen(die_type) 31 | val += 1 32 | return final_roll 33 | def test(): 34 | """Test criteria to show script works.""" 35 | 36 | _1d6 = multiDie(1,1) #1d6 37 | print("1d6 = ", _1d6, end=' ') 38 | _2d6 = multiDie(2,1) #2d6 39 | print("\n2d6 = ", _2d6, end=' ') 40 | _3d6 = multiDie(3,1) #3d6 41 | print("\n3d6 = ", _3d6, end=' ') 42 | _4d6 = multiDie(4,1) #4d6 43 | print("\n4d6 = ", _4d6, end=' ') 44 | _1d10 = multiDie(1,2) #1d10 45 | print("\n1d10 = ", _1d10, end=' ') 46 | _2d10 = multiDie(2,2) #2d10 47 | print("\n2d10 = ", _2d10, end=' ') 48 | _3d10 = multiDie(2,2) #3d10 49 | print("\n3d10 = ", _3d10, end=' ') 50 | _d100 = multiDie(1,3) #d100 51 | print("\n1d100 = ", _d100, end=' ') 52 | 53 | if __name__ == "__main__": #run test() if calling as a separate program 54 | test() 55 | -------------------------------------------------------------------------------- /Chapter01/first_funct.py: -------------------------------------------------------------------------------- 1 | >>> first_funct() 2 | 1 3 | 2 4 | -------------------------------------------------------------------------------- /Chapter01/first_module.py: -------------------------------------------------------------------------------- 1 | m1 2 | 3 | -------------------------------------------------------------------------------- /Chapter01/git_local_file.py: -------------------------------------------------------------------------------- 1 | git+https:///@#egg= 2 | 3 | -------------------------------------------------------------------------------- /Chapter01/git_tag.py: -------------------------------------------------------------------------------- 1 | git tag -a -m "" 2 | 3 | -------------------------------------------------------------------------------- /Chapter01/import_dice_roller.py: -------------------------------------------------------------------------------- 1 | >>> import Random_Dice_Roller 2 | >>> Random_Dice_Roller.test() 3 | 1d6 = 1 4 | 2d6 = 8 5 | 3d6 = 10 6 | 4d6 = 12 7 | 1d10 = 5 8 | 2d10 = 8 9 | 3d10 = 6 10 | 1d100 = 26 11 | -------------------------------------------------------------------------------- /Chapter01/import_math.py: -------------------------------------------------------------------------------- 1 | >>> import math 2 | 3 | -------------------------------------------------------------------------------- /Chapter01/inplace_build.py: -------------------------------------------------------------------------------- 1 | $ python setup.py build_ext --inplace 2 | 3 | -------------------------------------------------------------------------------- /Chapter01/manifest_template.py: -------------------------------------------------------------------------------- 1 | include *.txt 2 | recursive-include examples *.txt *.py 3 | prune examples/sample?/build 4 | -------------------------------------------------------------------------------- /Chapter01/math_import_all.py: -------------------------------------------------------------------------------- 1 | >>> from math import * 2 | >>> sin(45) 3 | 0.8509035245341184 4 | -------------------------------------------------------------------------------- /Chapter01/math_sin.py: -------------------------------------------------------------------------------- 1 | >>> math.sin(45) 2 | 0.8509035245341184 3 | -------------------------------------------------------------------------------- /Chapter01/nested_functions.py: -------------------------------------------------------------------------------- 1 | >>> def first_funct(): 2 | ... x = 1 3 | ... print(x) 4 | ... def second_funct(): 5 | ... x = 2 6 | ... print(x) 7 | ... second_funct() 8 | ... 9 | -------------------------------------------------------------------------------- /Chapter01/new_temp_dir.py: -------------------------------------------------------------------------------- 1 | $ tempdir=$(mktemp -d /tmp/wheelhouse-XXXXX) 2 | 3 | -------------------------------------------------------------------------------- /Chapter01/nuitka_module.py: -------------------------------------------------------------------------------- 1 | nuitka --module .py 2 | 3 | -------------------------------------------------------------------------------- /Chapter01/nuitka_recursive.py: -------------------------------------------------------------------------------- 1 | nuitka --module --recurse-directory= 2 | 3 | -------------------------------------------------------------------------------- /Chapter01/nuitka_setup.py: -------------------------------------------------------------------------------- 1 | nuitka --recurse-all .py 2 | 3 | -------------------------------------------------------------------------------- /Chapter01/package_tree.py: -------------------------------------------------------------------------------- 1 | video/ # Top-level package 2 | __init__.py # Top-level initialization 3 | formats/ # Sub-package for file formats 4 | __init__.py # Package-level initialization 5 | avi_in.py 6 | avi_out.py 7 | mpg2_in.py 8 | mpg2_out.py 9 | webm_in.py 10 | webm_out.py 11 | effects/ # Sub-package for video effects 12 | specialFX/ # Sub-package for special effects 13 | __init__.py 14 | sepia.py 15 | mosaic.py 16 | old_movie.py 17 | glass.py 18 | pencil.py 19 | tv.py 20 | transform/ # Sub-package for transform effects 21 | __init__.py 22 | flip.py 23 | skew.py 24 | rotate.py 25 | mirror.py 26 | wave.py 27 | broken_glass.py 28 | draw/ # Sub-package for draw effects 29 | __init__.py 30 | rectangle.py 31 | ellipse.py 32 | border.py 33 | line.py 34 | polygon.py 35 | -------------------------------------------------------------------------------- /Chapter01/pip_force_install.py: -------------------------------------------------------------------------------- 1 | $ pip install --force-reinstall --ignore-installed --upgrade --no-index --no-deps $tempdir/* 2 | -------------------------------------------------------------------------------- /Chapter01/pip_install.py: -------------------------------------------------------------------------------- 1 | pip install 2 | 3 | -------------------------------------------------------------------------------- /Chapter01/pip_install_latest.py: -------------------------------------------------------------------------------- 1 | $ pip install 2 | 3 | -------------------------------------------------------------------------------- /Chapter01/pip_install_minimum.py: -------------------------------------------------------------------------------- 1 | $ pip install " >= 1.1" 2 | 3 | -------------------------------------------------------------------------------- /Chapter01/pip_install_specific_version.py: -------------------------------------------------------------------------------- 1 | $ pip install ==1.2.2 2 | 3 | -------------------------------------------------------------------------------- /Chapter01/pip_local_wheel.py: -------------------------------------------------------------------------------- 1 | pip install /local_files/SomePackage-1.2-py2.py3-none-any.whl 2 | 3 | -------------------------------------------------------------------------------- /Chapter01/pip_outdated.py: -------------------------------------------------------------------------------- 1 | $ pip list --outdated 2 | docutils (Current: 0.10 Latest: 0.11) 3 | Sphinx (Current: 1.2.1 Latest: 1.2.2) 4 | -------------------------------------------------------------------------------- /Chapter01/pip_search.py: -------------------------------------------------------------------------------- 1 | $ pip search peppercorn 2 | pepperedform - Helpers for using peppercorn with formprocess. 3 | peppercorn - A library for converting a token stream into [...] 4 | -------------------------------------------------------------------------------- /Chapter01/pip_show.py: -------------------------------------------------------------------------------- 1 | $ pip show sphinx 2 | Name: Sphinx 3 | Version: 1.4.5 4 | Summary: Python documentation generator 5 | Home-page: http://sphinx-doc.org/ 6 | Author: Georg Brandl 7 | Author-email: georg@python.org 8 | License: BSD 9 | Location: /my/env/lib/python2.7/site-packages 10 | Requires: docutils, snowballstemmer, alabaster, Pygments, imagesize, Jinja2, babel, six 11 | -------------------------------------------------------------------------------- /Chapter01/pip_tmp_dir.py: -------------------------------------------------------------------------------- 1 | $ pip wheel -r requirements.txt --wheel-dir = $tempdir 2 | 3 | -------------------------------------------------------------------------------- /Chapter01/pip_wheel.py: -------------------------------------------------------------------------------- 1 | pip install 2 | 3 | -------------------------------------------------------------------------------- /Chapter01/pipenv_install.py: -------------------------------------------------------------------------------- 1 | >>> pipenv install 2 | 3 | -------------------------------------------------------------------------------- /Chapter01/pipenv_run.py: -------------------------------------------------------------------------------- 1 | >>>pipenv run python3 .py 2 | 3 | -------------------------------------------------------------------------------- /Chapter01/pipenv_shell.py: -------------------------------------------------------------------------------- 1 | cody@cody-Serval-WS ~ $ pipenv shell 2 | Creating a virtualenv for this project... 3 | ⠋Using base prefix '/usr/local' 4 | New python executable in 5 | /home/cody/.local/share/virtualenvs/cody-Vi_4YmwP/bin/python3.6 6 | Also creating executable in 7 | /home/cody/.local/share/virtualenvs/cody-Vi_4YmwP/bin/python 8 | Installing setuptools, pip, wheel...done. 9 | Virtualenv location: 10 | /home/cody/.local/share/virtualenvs/cody-Vi_4YmwP 11 | Creating a Pipfile for this project… 12 | Spawning environment shell (/bin/bash). Use 'exit' to leave. 13 | cody@cody-Serval-WS ~ $ source 14 | /home/cody/.local/share/virtualenvs/cody-Vi_4YmwP/bin/activate 15 | (cody-Vi_4YmwP) cody@cody-Serval-WS ~ $ 16 | -------------------------------------------------------------------------------- /Chapter01/pipfile.py: -------------------------------------------------------------------------------- 1 | [[source]] 2 | url = "https://pypi.python.org/simple" 3 | verify_ssl = true 4 | name = "pypi" 5 | 6 | [packages] 7 | requests = "*" 8 | 9 | 10 | [dev-packages] 11 | pytest = "*" 12 | -------------------------------------------------------------------------------- /Chapter01/pipfile_lock.py: -------------------------------------------------------------------------------- 1 | { 2 | "_meta": { 3 | "hash": { 4 | "sha256": "8d14434df45e0ef884d6c3f6e8048ba72335637a8631cc44792f52fd20b6f97a" 5 | }, 6 | "host-environment-markers": { 7 | "implementation_name": "cpython", 8 | "implementation_version": "3.6.1", 9 | "os_name": "posix", 10 | "platform_machine": "x86_64", 11 | "platform_python_implementation": "CPython", 12 | "platform_release": "16.7.0", 13 | "platform_system": "Darwin", 14 | "platform_version": "Darwin Kernel Version 16.7.0: Thu Jun 15 17:36:27 PDT 2017; root:xnu-3789.70.16~2/RELEASE_X86_64", 15 | "python_full_version": "3.6.1", 16 | "python_version": "3.6", 17 | "sys_platform": "darwin" 18 | }, 19 | "pipfile-spec": 5, 20 | "requires": {}, 21 | "sources": [ 22 | { 23 | "name": "pypi", 24 | "url": "https://pypi.python.org/simple", 25 | "verify_ssl": true 26 | } 27 | ] 28 | }, 29 | "default": { 30 | "certifi": { 31 | "hashes": [ 32 | "sha256:54a07c09c586b0e4c619f02a5e94e36619da8e2b053e20f594348c0611803704", 33 | "sha256:40523d2efb60523e113b44602298f0960e900388cf3bb6043f645cf57ea9e3f5" 34 | ], 35 | "version": "==2017.7.27.1" 36 | }, 37 | "chardet": { 38 | "hashes": [ 39 | "sha256:fc323ffcaeaed0e0a02bf4d117757b98aed530d9ed4531e3e15460124c106691", 40 | "sha256:84ab92ed1c4d4f16916e05906b6b75a6c0fb5db821cc65e70cbd64a3e2a5eaae" 41 | ], 42 | "version": "==3.0.4" 43 | }, 44 | 45 | ***further entries truncated*** 46 | -------------------------------------------------------------------------------- /Chapter01/print_enum.py: -------------------------------------------------------------------------------- 1 | >>> def print_input(*args): 2 | ... for val, input in enumerate(args): 3 | ... print("{}. {}".format(val, input)) 4 | ... 5 | >>> print_input("spam", "spam", "eggs", "spam") 6 | 0. spam 7 | 1. spam 8 | 2. eggs 9 | 3. spam 10 | -------------------------------------------------------------------------------- /Chapter01/print_funct.py: -------------------------------------------------------------------------------- 1 | def print_funct(arg): 2 | print(arg) 3 | if __name__ == "__main__": 4 | import sys 5 | print_funct(sys.argv[1]) 6 | -------------------------------------------------------------------------------- /Chapter01/print_mult_args.py: -------------------------------------------------------------------------------- 1 | def print_funct(arg1, arg2, arg3): 2 | print(arg1, arg2, arg3) 3 | if __name__ == "__main__": 4 | import sys 5 | print_funct(sys.argv[1], sys.argv[2], sys.argv[3]) 6 | -------------------------------------------------------------------------------- /Chapter01/project_hash.py: -------------------------------------------------------------------------------- 1 | FooProject == 1.2 --hash=sha256: 2 | 3 | -------------------------------------------------------------------------------- /Chapter01/py2exe_setup.py: -------------------------------------------------------------------------------- 1 | from distutils.core import setup 2 | import py2exe 3 | setup(console=['hello.py']) 4 | -------------------------------------------------------------------------------- /Chapter01/pyinstaller.py: -------------------------------------------------------------------------------- 1 | pyinstaller .py 2 | 3 | -------------------------------------------------------------------------------- /Chapter01/randint.py: -------------------------------------------------------------------------------- 1 | >>> randint(0, 1000) 2 | Traceback (most recent call last): 3 | File "", line 1, in 4 | NameError: name 'randint' is not defined 5 | >>> import random 6 | >>> random.randint(0, 1000) 7 | 607 8 | -------------------------------------------------------------------------------- /Chapter01/randrange.py: -------------------------------------------------------------------------------- 1 | >>> from random import randint 2 | >>> randint(0, 10) 3 | 2 4 | >>> randrange(0, 25) 5 | Traceback (most recent call last): 6 | File "", line 1, in 7 | NameError: name 'randrange' is not defined 8 | -------------------------------------------------------------------------------- /Chapter01/rel_imports.py: -------------------------------------------------------------------------------- 1 | from . import mosaic 2 | from .. import transform 3 | from .. draw import rectangle 4 | -------------------------------------------------------------------------------- /Chapter01/requirements_txt.py: -------------------------------------------------------------------------------- 1 | # 2 | ####### example-requirements.txt ####### 3 | # 4 | ###### Requirements without Version Specifiers ###### 5 | nose 6 | nose-cov 7 | beautifulsoup4 8 | # 9 | ###### Requirements with Version Specifiers ###### 10 | # See https://www.python.org/dev/peps/pep-0440/#version-specifiers 11 | docopt == 0.6.1 # Version Matching. Must be version 0.6.1 12 | keyring >= 4.1.1 # Minimum version 4.1.1 13 | coverage != 3.5 # Version Exclusion. Anything except version 3.5 14 | Mopidy-Dirble ~= 1.1 # Compatible release. Same as >= 1.1, == 1.* 15 | # 16 | ###### Refer to other requirements files ###### 17 | -r other-requirements.txt 18 | # 19 | # 20 | ###### A particular file ###### 21 | ./downloads/numpy-1.9.2-cp34-none-win32.whl 22 | http://wxpython.org/Phoenix/snapshot-builds/wxPython_Phoenix-3.0.3.dev1820+49a8884-cp34-none-win_amd64.whl 23 | # 24 | ###### Additional Requirements without Version Specifiers ###### 25 | # Same as 1st section, just here to show that you can put things in any order. 26 | rejected 27 | green 28 | # 29 | -------------------------------------------------------------------------------- /Chapter01/second_funct.py: -------------------------------------------------------------------------------- 1 | >>> second_funct() 2 | Traceback (most recent call last): 3 | File "", line 1, in 4 | NameError: name 'second_funct' is not defined 5 | -------------------------------------------------------------------------------- /Chapter01/second_module.py: -------------------------------------------------------------------------------- 1 | m2<1.7 2 | 3 | -------------------------------------------------------------------------------- /Chapter01/sin_no_import.py: -------------------------------------------------------------------------------- 1 | >>> sin(45) 2 | Traceback (most recent call last): 3 | File "", line 1, in 4 | NameError: name 'sin' is not defined 5 | -------------------------------------------------------------------------------- /Chapter01/tar_file.py: -------------------------------------------------------------------------------- 1 | $ (cd "$tempdir"; tar -cjvf "$cwd/.tar.bz2" *) 2 | 3 | -------------------------------------------------------------------------------- /Chapter01/temp_dir.py: -------------------------------------------------------------------------------- 1 | $ tempdir = $(mktemp -d /tmp/archive_dir) 2 | 3 | -------------------------------------------------------------------------------- /Chapter01/third_module.py: -------------------------------------------------------------------------------- 1 | m3>=1.5, <=2.0 2 | 3 | -------------------------------------------------------------------------------- /Chapter01/twine_error.py: -------------------------------------------------------------------------------- 1 | HTTPError: 403 Client Error: You are not allowed to edit 'xyz' package information 2 | -------------------------------------------------------------------------------- /Chapter01/twine_registration.py: -------------------------------------------------------------------------------- 1 | twine register dist/..tar.gz 2 | twine register dist/----.whl 3 | -------------------------------------------------------------------------------- /Chapter01/twine_upload.py: -------------------------------------------------------------------------------- 1 | twine upload dist/* 2 | 3 | -------------------------------------------------------------------------------- /Chapter01/universal_wheel.py: -------------------------------------------------------------------------------- 1 | python setup.py bdist_wheel --universal 2 | 3 | -------------------------------------------------------------------------------- /Chapter01/untar_file.py: -------------------------------------------------------------------------------- 1 | $ (cd $tempdir; tar -xvf /path/to/.tar.bz2) 2 | 3 | -------------------------------------------------------------------------------- /Chapter01/versioning.py: -------------------------------------------------------------------------------- 1 | 2.1.0.dev1 # Development release 2 | 2.1.0a1 # Alpha Release 3 | 2.1.0b1 # Beta Release 4 | 2.1.0rc1 # Release Candidate 5 | 2.1.0 # Final Release 6 | 2.1.0.post1 # Post Release 7 | 2018.04 # Date based release 8 | 19 # Serial release 9 | -------------------------------------------------------------------------------- /Chapter01/wheel_create.py: -------------------------------------------------------------------------------- 1 | python setup.py sdist bdist_wheel --universal 2 | 3 | -------------------------------------------------------------------------------- /Chapter02/apt_install_package.py: -------------------------------------------------------------------------------- 1 | $ sudo apt install python[3]- 2 | 3 | -------------------------------------------------------------------------------- /Chapter02/bpython_requirements.py: -------------------------------------------------------------------------------- 1 | $ cd bpython 2 | $ pip install -e . # installs bpython and necessary dependencies 3 | $ pip install watchdog urwid # install optional dependencies 4 | $ pip install sphinx mock nose # install development dependencies 5 | $ bpython # launch bpython 6 | -------------------------------------------------------------------------------- /Chapter02/bypthon_clone.py: -------------------------------------------------------------------------------- 1 | $ git clone git@github.com:/bpython.git 2 | 3 | -------------------------------------------------------------------------------- /Chapter02/bypthon_install.py: -------------------------------------------------------------------------------- 1 | $ virtualenv bpython-dev # determines Python version used 2 | $ source bpython-dev/bin/activate # necessary every time you work on bpython 3 | -------------------------------------------------------------------------------- /Chapter02/call_module.py: -------------------------------------------------------------------------------- 1 | $ python -m random 2 | 3 | -------------------------------------------------------------------------------- /Chapter02/command_opts.py: -------------------------------------------------------------------------------- 1 | python [-bBdEhiIOqsSuvVWx?] [-c command | -m module-name | script | - ] [args] 2 | 3 | -------------------------------------------------------------------------------- /Chapter02/dreampie_clone.py: -------------------------------------------------------------------------------- 1 | git clone https://github.com/noamraph/dreampie.git 2 | 3 | -------------------------------------------------------------------------------- /Chapter02/exec_script.py: -------------------------------------------------------------------------------- 1 | $ python .py 2 | 3 | -------------------------------------------------------------------------------- /Chapter02/interactive_mode.py: -------------------------------------------------------------------------------- 1 | $ python 2 | Python 3.6.3 |Anaconda, Inc.| (default, Oct 13 2017, 12:02:49) [GCC 7.2.0] on linux 3 | Type "help", "copyright", "credits" or "license" for more information. 4 | >>> 5 | -------------------------------------------------------------------------------- /Chapter02/ipython_prompt.py: -------------------------------------------------------------------------------- 1 | $ ipython 2 | Python 3.6.3 |Anaconda, Inc.| (default, Oct 13 2017, 12:02:49) 3 | Type 'copyright', 'credits' or 'license' for more information 4 | IPython 6.1.0 – An enhanced Interactive Python. Type '?' for help. 5 | In [1]: 6 | -------------------------------------------------------------------------------- /Chapter02/ironpython_install.py: -------------------------------------------------------------------------------- 1 | Install-Package IronPython 2 | Install-Package IronPython.StdLib 3 | -------------------------------------------------------------------------------- /Chapter02/jupyter_install.py: -------------------------------------------------------------------------------- 1 | $ python -m pip install ipykernel 2 | $ python -m ipykernel install [--user] [--name ] [--display-name <"User Friendly Name">] 3 | -------------------------------------------------------------------------------- /Chapter02/jython_console.py: -------------------------------------------------------------------------------- 1 | java -jar jython_installer-2.7.1.jar --console 2 | -------------------------------------------------------------------------------- /Chapter02/jython_install.py: -------------------------------------------------------------------------------- 1 | java -jar jython_installer-2.7.1.jar 2 | -------------------------------------------------------------------------------- /Chapter02/make_html.py: -------------------------------------------------------------------------------- 1 | $ make -C doc/sphinx html 2 | 3 | -------------------------------------------------------------------------------- /Chapter02/micropython.py: -------------------------------------------------------------------------------- 1 | $ git submodule update --init 2 | $ cd ports/unix 3 | $ make axtls 4 | $ make 5 | -------------------------------------------------------------------------------- /Chapter02/os_environ.py: -------------------------------------------------------------------------------- 1 | >>> os.environ["PYTHONOPTIMIZE"] = "1" 2 | 3 | -------------------------------------------------------------------------------- /Chapter02/print_path.py: -------------------------------------------------------------------------------- 1 | >>> print(os.environ["PATH"]) 2 | /home/cody/anaconda3/bin:/home/cody/bin:/home/cody/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games 3 | -------------------------------------------------------------------------------- /Chapter02/read_startup.py: -------------------------------------------------------------------------------- 1 | if os.path.isfile('.pythonrc.py'): exec(open('.pythonrc.py').read() 2 | 3 | -------------------------------------------------------------------------------- /Chapter02/run_command.py: -------------------------------------------------------------------------------- 1 | $ python -c "print('Hello World')" 2 | 3 | -------------------------------------------------------------------------------- /Chapter02/run_ipython.py: -------------------------------------------------------------------------------- 1 | $ pip install ipython 2 | 3 | -------------------------------------------------------------------------------- /Chapter02/run_script.py: -------------------------------------------------------------------------------- 1 | $ python