├── mp58_urlspy_order ├── pianos │ ├── __init__.py │ ├── migrations │ │ └── __init__.py │ ├── models.py │ ├── admin.py │ ├── tests.py │ ├── apps.py │ ├── urls.py │ └── views.py ├── synths │ ├── __init__.py │ ├── migrations │ │ └── __init__.py │ ├── models.py │ ├── admin.py │ ├── tests.py │ ├── apps.py │ ├── urls.py │ └── views.py ├── piano_store │ ├── __init__.py │ ├── urls.py │ ├── asgi.py │ └── wsgi.py ├── .gitignore ├── synths_ursl_tried.txt └── manage.py ├── mp23_grounding_part_2 ├── hello.txt ├── willie_mountains.png └── partial_programs │ ├── add_border_1.py │ ├── add_border_3.py │ ├── add_border_2.py │ ├── add_border_4.py │ ├── add_border_5.py │ └── add_border_6.py ├── mp149_debugging_8 ├── requirements.in ├── card_data.py └── card_models.py ├── mp150_debugging_9 ├── requirements.in ├── card_data.py └── demo_cards.py ├── mp154_debugging_11 ├── requirements.in ├── card_data.py ├── demo_cards.py └── go_fish_utils.py ├── mp156_debugging_13 ├── requirements.in ├── .gitignore ├── card_data.py └── demo_cards.py ├── mp55_oop13_serialization_abc ├── robot.json ├── robot_dict.py ├── robot_class.py ├── robot_class_write.py └── robot_class_read.py ├── mp143_debugging_4 ├── requirements.in ├── .gitignore ├── tests │ └── e2e_tests │ │ └── conftest.py ├── die.py ├── dice_battle.py └── utils.py ├── mp151_debugging_10 ├── cards_with_error │ ├── requirements.in │ ├── card_data.py │ └── demo_cards.py ├── go_fish_fixed │ ├── requirements.in │ ├── card_data.py │ ├── demo_cards.py │ └── go_fish.py └── go_fish_with_error │ ├── requirements.in │ ├── card_data.py │ ├── demo_cards.py │ └── go_fish.py ├── mp155_debugging_12 ├── go_fish_bugfix │ ├── requirements.in │ ├── .gitignore │ ├── card_data.py │ └── demo_cards.py └── go_fish_seeded │ ├── requirements.in │ ├── .gitignore │ ├── card_data.py │ └── demo_cards.py ├── mp24_grounding_part_3 ├── tests │ ├── source_images │ │ ├── hello.txt │ │ ├── bear_scratching.jpg │ │ ├── bear_scratching_bordered.jpg │ │ └── bear_scratching_original_size.jpg │ └── reference_images │ │ ├── bear_scratching_default.jpg │ │ ├── bear_scratching_15px_border.jpg │ │ ├── bear_scratching_15px_padding.jpg │ │ ├── bear_scratching_black_border.jpg │ │ └── bear_scratching_20px_border_15px_padding.jpg ├── partial_programs │ ├── tests_0 │ │ ├── source_images │ │ │ ├── hello.txt │ │ │ └── bear_scratching.jpg │ │ └── reference_images │ │ │ ├── bear_scratching_bordered_default.jpg │ │ │ └── bear_scratching_bordered_default_15px_border.jpg │ ├── tests_10 │ │ ├── source_images │ │ │ ├── hello.txt │ │ │ ├── bear_scratching.jpg │ │ │ └── bear_scratching_original_size.jpg │ │ └── reference_images │ │ │ ├── bear_scratching_default.jpg │ │ │ ├── bear_scratching_15px_border.jpg │ │ │ ├── bear_scratching_15px_padding.jpg │ │ │ ├── bear_scratching_black_border.jpg │ │ │ └── bear_scratching_20px_border_15px_padding.jpg │ ├── tests_4 │ │ ├── source_images │ │ │ ├── hello.txt │ │ │ └── bear_scratching.jpg │ │ └── reference_images │ │ │ ├── bear_scratching_bordered_default.jpg │ │ │ └── bear_scratching_bordered_default_15px_border.jpg │ ├── add_border_11.py │ ├── add_border_9.py │ ├── cli_5.py │ ├── add_border_5.py │ ├── image_functions_9.py │ ├── cli_11.py │ ├── add_border_6.py │ ├── cli_10.py │ └── add_border_7.py ├── bear_scratching.jpg ├── bear_scratching_bordered.jpg ├── add_border.py └── image_functions.py ├── mp26_grounding_part_4 ├── tests │ ├── source_images │ │ ├── hello.txt │ │ ├── bear_scratching.jpg │ │ └── bear_scratching_original_size.jpg │ └── reference_images │ │ ├── bear_scratching_default.jpg │ │ ├── bear_scratching_15px_border.jpg │ │ ├── bear_scratching_15px_padding.jpg │ │ ├── bear_scratching_black_border.jpg │ │ └── bear_scratching_20px_border_15px_padding.jpg ├── partial_programs │ ├── tests_0 │ │ ├── source_images │ │ │ ├── hello.txt │ │ │ └── bear_scratching.jpg │ │ └── reference_images │ │ │ ├── bear_scratching_default.jpg │ │ │ ├── bear_scratching_15px_border.jpg │ │ │ ├── bear_scratching_15px_padding.jpg │ │ │ ├── bear_scratching_black_border.jpg │ │ │ └── bear_scratching_20px_border_15px_padding.jpg │ ├── tests_2 │ │ ├── source_images │ │ │ ├── hello.txt │ │ │ └── bear_scratching.jpg │ │ └── reference_images │ │ │ ├── bear_scratching_default.jpg │ │ │ ├── bear_scratching_15px_border.jpg │ │ │ ├── bear_scratching_15px_padding.jpg │ │ │ ├── bear_scratching_black_border.jpg │ │ │ └── bear_scratching_20px_border_15px_padding.jpg │ ├── tests_4 │ │ ├── source_images │ │ │ ├── hello.txt │ │ │ └── bear_scratching.jpg │ │ └── reference_images │ │ │ ├── bear_scratching_default.jpg │ │ │ ├── bear_scratching_15px_border.jpg │ │ │ ├── bear_scratching_15px_padding.jpg │ │ │ ├── bear_scratching_black_border.jpg │ │ │ └── bear_scratching_20px_border_15px_padding.jpg │ ├── main_3.py │ ├── cli_args_1.py │ ├── cli_args_2.py │ ├── main_2.py │ ├── main_1.py │ ├── cli_args_3.py │ ├── image_processing_1.py │ ├── image_processing_3.py │ └── cli_args_4.py ├── willie_sideeye.jpg ├── willie_sideeye_original.jpg ├── full_gpt_session_refactoring_add_border.png ├── main.py ├── image_processing.py └── cli_args.py ├── mp85_calc_file_paths ├── coffees.txt ├── dunder_file_demo.py ├── dunder_file_demo_2_parent.py ├── coffee_reader.py ├── coffee_reader_3_dunder_file.py ├── coffee_reader_2_absolute_path.py └── coffee_reader_4_project_root.py ├── mp5_lists_closer_look ├── squares_twenty_million.py ├── squares_comprehension.py ├── squares_twenty_million_genexpr.py ├── squares_twenty_million_append.py ├── squares.py └── squares_twenty_million_append_tempvar.py ├── mp148_min_rep_example ├── open_python_org.py └── rolling_dice │ ├── die.py │ └── die_visual.py ├── mp124_real_estate_images ├── output_images │ └── placeholder.txt ├── image_archiver_0_naive.py ├── image_archiver_1_selenium.py ├── image_archiver_2_click_first_image.py └── image_archiver_3_first_full_image.py ├── assets └── dice_battle_mp143.zip ├── mp130_door_codes ├── key_code_0_one_liner.py ├── key_code_1_sequence.py ├── key_code_2_cli.py ├── key_code_3_repeated_digits.py └── key_code_4_refactored.py ├── mp16_ending_while_loops ├── ten_squares.py ├── ten_squares_break.py └── ten_squares_flag.py ├── mp65_october_wx ├── october_highs.png ├── october_highs_lows.png ├── october_rolling_temps.png ├── october_temps.py ├── october_temps_2_october_data.py └── october_temps_3_plot_highs.py ├── mp8_lists_closer_look_lists_tuples ├── straight_cards_list.py ├── straight_cards_tuple.py ├── primes_list.py ├── primes_tuple.py ├── poker_hands.py ├── poker_hands_check_ace_high_4_using_all.py ├── poker_hands_check_ace_high.py ├── poker_hands_check_ace_high_2_all_cards_tuple.py ├── poker_hands_check_ace_high_3_hand_as_tuple.py └── list_tuple_size_comparison.py ├── mp128_checking_attributes ├── wx_observer.py ├── wx_observer_wind.py ├── wx_model.py ├── wx_model_wind.py ├── wx_reporter.py ├── wx_reporter_3_hasattr.py └── wx_reporter_2_try_except.py ├── mp78_streamlit_basics ├── roller.py ├── roller_st_write.py ├── roller_button.py ├── roller_radio.py ├── roller_num_dice_slider.py ├── roller_chart.py └── roller_sidebar.py ├── mp31_importance_profiling ├── output │ ├── high_temps.png │ ├── high_temps_1_year_moving_average.png │ ├── high_temps_3_year_moving_average.png │ ├── high_temps_5_year_moving_average.png │ ├── high_temps_10_year_moving_average.png │ └── high_temps_30_year_moving_average.png └── high_temp_trends.py ├── mp32_importance_profiling ├── output │ ├── high_temps.png │ ├── high_temps_1_year_moving_average.png │ ├── high_temps_3_year_moving_average.png │ ├── high_temps_5_year_moving_average.png │ ├── high_temps_10_year_moving_average.png │ └── high_temps_30_year_moving_average.png └── high_temp_trends.py ├── mp57_exception_hierarchy ├── bad_list.py ├── bad_list_2_help.py ├── bad_list_5_mro.py ├── bad_list_4_catch_lookuperror.py └── bad_list_3_isinstance.py ├── mp97_snippets ├── processed_snippets │ └── plot_data.png ├── raw_snippets │ └── plot_data.py └── pygparser.py ├── README.md ├── mp34_popular_projects ├── git-sim-merge_06-11-23_15-58-27.jpg └── git-sim-merge_06-11-23_16-00-42.mp4 ├── mp89_breakpoint ├── subscriber_ids.csv ├── subscribers.csv ├── generate_import_file.py ├── generate_import_file_2_read_csv.py ├── generate_import_file_3_breakpoint.py └── generate_import_file_4_fill_datacass.py ├── mp20_list_gotchas ├── wild_cards.py ├── card_game_one_player.py ├── dealer.py ├── fixed │ ├── dealer.py │ ├── card_game_two_players.py │ └── player.py ├── card_game_two_players.py └── player.py ├── mp9_chatgpt_not_reliable_teacher ├── winners.py ├── winners_ranked.py └── winners_bizarre_chatgpt_loop.py ├── mp33_using_pandas ├── output │ ├── high_temps_10_year_moving_average.png │ ├── high_temps_1_year_moving_average.png │ ├── high_temps_30_year_moving_average.png │ ├── high_temps_3_year_moving_average.png │ └── high_temps_5_year_moving_average.png ├── high_temp_trends.py └── high_temp_trends_show_invalid.py ├── mp47_oop8_comparison_methods ├── river.py ├── river_2_greater_than.py └── river_3_lt_eq.py ├── mp39_oop3_init ├── greeter.py ├── greeter_4_initialize_object.py ├── greeter_2_tone.py └── greeter_3_misspelled.py ├── mp6_searching_quick_answers ├── my_great_ide.py ├── my_great_ide_index.py └── my_great_ide_enumerate.py ├── .gitignore ├── mp37_oop2_self ├── squares.py ├── robot.py ├── squares_dict.py ├── robot_print_self.py ├── robot_army.py ├── robot_potato.py ├── robot_print_self_2.py ├── robot_print_self_3.py ├── robot_expanded.py ├── robot_self_dict.py └── robot_no_self.py ├── mp49_oop9_helper_methods ├── chessboard.py ├── chessboard_2.py ├── chessboard_3.py └── chessboard_4.py ├── mp13_lists_sets ├── explore_responses.py ├── explore_responses_set.py └── explore_responses_naive.py ├── mp2_lists_closer_look ├── bookshelf.py └── bookshelf.c ├── mp15_lists_arguments ├── generate_requests.py ├── process_requests.py └── process_requests_protected.py ├── mp46_oop7_new ├── nonzero_list.py ├── nonzero_tuple.py ├── nonzero_tuple_2.py └── nonzero_list_2.py ├── mp19_improving_code_blocks ├── partial_programs │ ├── email_parser_1.py │ ├── email_parser_2.py │ ├── email_parser_3.py │ └── email_parser_4.py ├── raw_post_without_title.html ├── raw_post.html └── highlighting_lines │ └── raw_post.html ├── mp29_settings ├── small_examples.py ├── alien.py ├── partial_programs │ ├── alien_3.py │ ├── alien_1.py │ ├── game_0.py │ ├── game_1.py │ ├── game_2.py │ └── game_3.py └── game.py ├── mp126_function_checklist ├── fn_checklist_0_parse_file.py ├── fn_checklist_1_no_comprehension.py ├── fn_checklist_6_simpler_approach.py ├── fn_checklist_2_all_fn_names.py ├── fn_checklist_3_no_comprehension.py ├── fn_checklist_4_task_list.py └── fn_checklist_5_pass_filename.py ├── mp12_lists_arrays └── best_sequence.py ├── mp44_oop6_str_repr ├── bonsai.py ├── bonsai_2.py └── bonsai_3.py ├── mp10_lists_profiling ├── sum_squares_optimize_get_sum.py ├── sum_squares_optimize_get_squares.py └── sum_squares.py ├── mp42_oop5_class_methods ├── trees.py ├── trees_2.py ├── trees_5.py ├── trees_4.py ├── trees_3_tracking_instances.py ├── trees_7.py ├── trees_6.py └── trees_8_doesnt_work.py ├── mp41_static_methods ├── mountains.py ├── mountains_5_call_from_class.py ├── mountains_2_disclaimer.py ├── mountains_3_disclaimer_no_self_error.py └── mountains_4_static_method.py ├── mp7_tracking_down_a_bug ├── die.py └── die_visual.py ├── mp61_oop16 ├── triangle_nums.py ├── triangle_nums_2_print_fig_ax.py ├── triangle_nums_3_facecolor.py └── triangle_nums_4_text.py ├── mp3_lists_closer_look ├── random_numbers_insert.py ├── list_memory.py ├── random_numbers_deque.py ├── random_numbers.py └── list_memory_visual.py ├── mp43_substack_notes_cguo ├── main.py └── main_2.py ├── mp17_lists_modifying_in_loop ├── process_requests_good.py ├── process_requests_gotcha.py ├── process_requests_good_multiline.py ├── process_requests_good_full_loop.py └── process_requests_gotcha_diagnostic.py ├── oop_18 ├── partial_versions │ ├── climbing_library_0.py │ ├── climbing_library_1_lend_book.py │ ├── library_models_0.py │ └── library_models_1_get_status.py └── climbing_library.py ├── oop_19 ├── office_hours_monitor.py └── office_hours_monitor_oop.py ├── mp145_debugging_6 └── strat_players.py ├── mp120_lotteries ├── nc_powerball.py └── nc_powerball_2_30_plays.py ├── mp48_radians_function ├── squares_degrees.py └── squares_radians.py ├── mp52_oop11_inheritance ├── account.py ├── account_2_free.py ├── account_4_account_hardcoded.py └── account_3_print_super.py ├── mp68_gift_exchange └── gift_exchange_2_check_match.py ├── mp21_list_deepcopy ├── locations.py └── locations_deepcopy.py ├── mp123_mortgages ├── mortgage_analysis_0.py └── mortgage_analysis_1.py ├── oop_17 └── library.py └── mp53_oop12_abc ├── account_4_invisible.py ├── account_3_not_well_behaved.py ├── account.py └── account_5_assertive_account.py /mp58_urlspy_order/pianos/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /mp58_urlspy_order/synths/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /mp23_grounding_part_2/hello.txt: -------------------------------------------------------------------------------- 1 | Hello! 2 | -------------------------------------------------------------------------------- /mp58_urlspy_order/piano_store/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /mp149_debugging_8/requirements.in: -------------------------------------------------------------------------------- 1 | pytest 2 | -------------------------------------------------------------------------------- /mp150_debugging_9/requirements.in: -------------------------------------------------------------------------------- 1 | pytest 2 | -------------------------------------------------------------------------------- /mp154_debugging_11/requirements.in: -------------------------------------------------------------------------------- 1 | pytest 2 | -------------------------------------------------------------------------------- /mp156_debugging_13/requirements.in: -------------------------------------------------------------------------------- 1 | pytest 2 | -------------------------------------------------------------------------------- /mp58_urlspy_order/pianos/migrations/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /mp58_urlspy_order/synths/migrations/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /mp55_oop13_serialization_abc/robot.json: -------------------------------------------------------------------------------- 1 | {"name": "Marvin"} -------------------------------------------------------------------------------- /mp143_debugging_4/requirements.in: -------------------------------------------------------------------------------- 1 | pytest 2 | python-bugger 3 | -------------------------------------------------------------------------------- /mp151_debugging_10/cards_with_error/requirements.in: -------------------------------------------------------------------------------- 1 | pytest 2 | -------------------------------------------------------------------------------- /mp151_debugging_10/go_fish_fixed/requirements.in: -------------------------------------------------------------------------------- 1 | pytest 2 | -------------------------------------------------------------------------------- /mp155_debugging_12/go_fish_bugfix/requirements.in: -------------------------------------------------------------------------------- 1 | pytest 2 | -------------------------------------------------------------------------------- /mp155_debugging_12/go_fish_seeded/requirements.in: -------------------------------------------------------------------------------- 1 | pytest 2 | -------------------------------------------------------------------------------- /mp24_grounding_part_3/tests/source_images/hello.txt: -------------------------------------------------------------------------------- 1 | Hello! 2 | -------------------------------------------------------------------------------- /mp26_grounding_part_4/tests/source_images/hello.txt: -------------------------------------------------------------------------------- 1 | Hello! 2 | -------------------------------------------------------------------------------- /mp151_debugging_10/go_fish_with_error/requirements.in: -------------------------------------------------------------------------------- 1 | pytest 2 | -------------------------------------------------------------------------------- /mp24_grounding_part_3/partial_programs/tests_0/source_images/hello.txt: -------------------------------------------------------------------------------- 1 | Hello! 2 | -------------------------------------------------------------------------------- /mp24_grounding_part_3/partial_programs/tests_10/source_images/hello.txt: -------------------------------------------------------------------------------- 1 | Hello! 2 | -------------------------------------------------------------------------------- /mp24_grounding_part_3/partial_programs/tests_4/source_images/hello.txt: -------------------------------------------------------------------------------- 1 | Hello! 2 | -------------------------------------------------------------------------------- /mp26_grounding_part_4/partial_programs/tests_0/source_images/hello.txt: -------------------------------------------------------------------------------- 1 | Hello! 2 | -------------------------------------------------------------------------------- /mp26_grounding_part_4/partial_programs/tests_2/source_images/hello.txt: -------------------------------------------------------------------------------- 1 | Hello! 2 | -------------------------------------------------------------------------------- /mp26_grounding_part_4/partial_programs/tests_4/source_images/hello.txt: -------------------------------------------------------------------------------- 1 | Hello! 2 | -------------------------------------------------------------------------------- /mp85_calc_file_paths/coffees.txt: -------------------------------------------------------------------------------- 1 | Hair Bender 2 | El Inierto Bourbon 3 | Trapper Creek -------------------------------------------------------------------------------- /mp143_debugging_4/.gitignore: -------------------------------------------------------------------------------- 1 | __pycache__ 2 | .venv/ 3 | *.pyc 4 | 5 | .DS_Store 6 | 7 | -------------------------------------------------------------------------------- /mp5_lists_closer_look/squares_twenty_million.py: -------------------------------------------------------------------------------- 1 | squares = [x**2 for x in range(20_000_000)] -------------------------------------------------------------------------------- /mp156_debugging_13/.gitignore: -------------------------------------------------------------------------------- 1 | .venv/ 2 | __pycache__/ 3 | 4 | .DS_Store 5 | 6 | *.egg-info/ 7 | -------------------------------------------------------------------------------- /mp148_min_rep_example/open_python_org.py: -------------------------------------------------------------------------------- 1 | import webbrowser 2 | webbrowser.open("https://python.org") -------------------------------------------------------------------------------- /mp58_urlspy_order/.gitignore: -------------------------------------------------------------------------------- 1 | __pycache__/ 2 | 3 | *.sqlite3 4 | 5 | .venv/ 6 | 7 | .DS_Store 8 | -------------------------------------------------------------------------------- /mp58_urlspy_order/pianos/models.py: -------------------------------------------------------------------------------- 1 | from django.db import models 2 | 3 | # Create your models here. 4 | -------------------------------------------------------------------------------- /mp58_urlspy_order/synths/models.py: -------------------------------------------------------------------------------- 1 | from django.db import models 2 | 3 | # Create your models here. 4 | -------------------------------------------------------------------------------- /mp58_urlspy_order/pianos/admin.py: -------------------------------------------------------------------------------- 1 | from django.contrib import admin 2 | 3 | # Register your models here. 4 | -------------------------------------------------------------------------------- /mp58_urlspy_order/pianos/tests.py: -------------------------------------------------------------------------------- 1 | from django.test import TestCase 2 | 3 | # Create your tests here. 4 | -------------------------------------------------------------------------------- /mp58_urlspy_order/synths/admin.py: -------------------------------------------------------------------------------- 1 | from django.contrib import admin 2 | 3 | # Register your models here. 4 | -------------------------------------------------------------------------------- /mp58_urlspy_order/synths/tests.py: -------------------------------------------------------------------------------- 1 | from django.test import TestCase 2 | 3 | # Create your tests here. 4 | -------------------------------------------------------------------------------- /mp5_lists_closer_look/squares_comprehension.py: -------------------------------------------------------------------------------- 1 | squares = [x**2 for x in range(1, 101)] 2 | print(squares) -------------------------------------------------------------------------------- /mp5_lists_closer_look/squares_twenty_million_genexpr.py: -------------------------------------------------------------------------------- 1 | squares_genexpr = (x**2 for x in range(20_000_000)) -------------------------------------------------------------------------------- /mp124_real_estate_images/output_images/placeholder.txt: -------------------------------------------------------------------------------- 1 | Placeholder file to include output_images/ in repository. -------------------------------------------------------------------------------- /mp155_debugging_12/go_fish_bugfix/.gitignore: -------------------------------------------------------------------------------- 1 | .venv/ 2 | __pycache__/ 3 | 4 | .DS_Store 5 | 6 | *.egg-info/ 7 | -------------------------------------------------------------------------------- /mp155_debugging_12/go_fish_seeded/.gitignore: -------------------------------------------------------------------------------- 1 | .venv/ 2 | __pycache__/ 3 | 4 | .DS_Store 5 | 6 | *.egg-info/ 7 | -------------------------------------------------------------------------------- /mp85_calc_file_paths/dunder_file_demo.py: -------------------------------------------------------------------------------- 1 | from pathlib import Path 2 | 3 | path = Path(__file__) 4 | print(path) -------------------------------------------------------------------------------- /assets/dice_battle_mp143.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ehmatthes/mostly_python/HEAD/assets/dice_battle_mp143.zip -------------------------------------------------------------------------------- /mp130_door_codes/key_code_0_one_liner.py: -------------------------------------------------------------------------------- 1 | from random import randint 2 | 3 | keycode = randint(0,999999) 4 | print(keycode) 5 | -------------------------------------------------------------------------------- /mp16_ending_while_loops/ten_squares.py: -------------------------------------------------------------------------------- 1 | x = 1 2 | while x < 11: 3 | square = x**2 4 | print(square) 5 | 6 | x += 1 -------------------------------------------------------------------------------- /mp5_lists_closer_look/squares_twenty_million_append.py: -------------------------------------------------------------------------------- 1 | squares = [] 2 | for x in range(20_000_000): 3 | squares.append(x**2) -------------------------------------------------------------------------------- /mp65_october_wx/october_highs.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ehmatthes/mostly_python/HEAD/mp65_october_wx/october_highs.png -------------------------------------------------------------------------------- /mp8_lists_closer_look_lists_tuples/straight_cards_list.py: -------------------------------------------------------------------------------- 1 | for _ in range(5000000): 2 | cards = [10, 'j', 'q', 'k', 'a'] 3 | -------------------------------------------------------------------------------- /mp8_lists_closer_look_lists_tuples/straight_cards_tuple.py: -------------------------------------------------------------------------------- 1 | for _ in range(5000000): 2 | cards = (10, 'j', 'q', 'k', 'a') 3 | -------------------------------------------------------------------------------- /mp128_checking_attributes/wx_observer.py: -------------------------------------------------------------------------------- 1 | from wx_model import WeatherObservation 2 | 3 | wx_obs = WeatherObservation(2.5, 1.5) 4 | -------------------------------------------------------------------------------- /mp65_october_wx/october_highs_lows.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ehmatthes/mostly_python/HEAD/mp65_october_wx/october_highs_lows.png -------------------------------------------------------------------------------- /mp23_grounding_part_2/willie_mountains.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ehmatthes/mostly_python/HEAD/mp23_grounding_part_2/willie_mountains.png -------------------------------------------------------------------------------- /mp24_grounding_part_3/bear_scratching.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ehmatthes/mostly_python/HEAD/mp24_grounding_part_3/bear_scratching.jpg -------------------------------------------------------------------------------- /mp26_grounding_part_4/willie_sideeye.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ehmatthes/mostly_python/HEAD/mp26_grounding_part_4/willie_sideeye.jpg -------------------------------------------------------------------------------- /mp65_october_wx/october_rolling_temps.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ehmatthes/mostly_python/HEAD/mp65_october_wx/october_rolling_temps.png -------------------------------------------------------------------------------- /mp85_calc_file_paths/dunder_file_demo_2_parent.py: -------------------------------------------------------------------------------- 1 | from pathlib import Path 2 | 3 | path = Path(__file__).parent / "coffees.txt" 4 | print(path) -------------------------------------------------------------------------------- /mp128_checking_attributes/wx_observer_wind.py: -------------------------------------------------------------------------------- 1 | from wx_model_wind import WeatherObservation 2 | 3 | wx_obs = WeatherObservation(0.5, 23.0, 15.0) 4 | -------------------------------------------------------------------------------- /mp78_streamlit_basics/roller.py: -------------------------------------------------------------------------------- 1 | from random import randint 2 | import streamlit as st 3 | 4 | roll = randint(1, 6) 5 | 6 | f"You rolled a {roll}." -------------------------------------------------------------------------------- /mp31_importance_profiling/output/high_temps.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ehmatthes/mostly_python/HEAD/mp31_importance_profiling/output/high_temps.png -------------------------------------------------------------------------------- /mp32_importance_profiling/output/high_temps.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ehmatthes/mostly_python/HEAD/mp32_importance_profiling/output/high_temps.png -------------------------------------------------------------------------------- /mp57_exception_hierarchy/bad_list.py: -------------------------------------------------------------------------------- 1 | python_exceptions = [ 2 | "SyntaxError", 3 | "NameError", 4 | ] 5 | 6 | my_exception = python_exceptions[2] -------------------------------------------------------------------------------- /mp5_lists_closer_look/squares.py: -------------------------------------------------------------------------------- 1 | squares = [] 2 | for x in range(1, 101): 3 | square = x**2 4 | squares.append(square) 5 | 6 | print(squares) -------------------------------------------------------------------------------- /mp97_snippets/processed_snippets/plot_data.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ehmatthes/mostly_python/HEAD/mp97_snippets/processed_snippets/plot_data.png -------------------------------------------------------------------------------- /mp26_grounding_part_4/willie_sideeye_original.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ehmatthes/mostly_python/HEAD/mp26_grounding_part_4/willie_sideeye_original.jpg -------------------------------------------------------------------------------- /mp85_calc_file_paths/coffee_reader.py: -------------------------------------------------------------------------------- 1 | from pathlib import Path 2 | 3 | path = Path("coffees.txt") 4 | contents = path.read_text() 5 | 6 | print(contents) -------------------------------------------------------------------------------- /mp24_grounding_part_3/bear_scratching_bordered.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ehmatthes/mostly_python/HEAD/mp24_grounding_part_3/bear_scratching_bordered.jpg -------------------------------------------------------------------------------- /mp5_lists_closer_look/squares_twenty_million_append_tempvar.py: -------------------------------------------------------------------------------- 1 | squares = [] 2 | for x in range(20_000_000): 3 | square = x**2 4 | squares.append(square) -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Mostly Python 2 | === 3 | 4 | This is a repository for code files mentioned in the [Mostly Python](https://mostlypython.substack.com) newsletter. 5 | 6 | -------------------------------------------------------------------------------- /mp128_checking_attributes/wx_model.py: -------------------------------------------------------------------------------- 1 | from dataclasses import dataclass 2 | 3 | @dataclass 4 | class WeatherObservation: 5 | precip: float 6 | temp: float 7 | -------------------------------------------------------------------------------- /mp16_ending_while_loops/ten_squares_break.py: -------------------------------------------------------------------------------- 1 | x = 1 2 | while True: 3 | square = x**2 4 | print(square) 5 | 6 | x += 1 7 | if x > 10: 8 | break -------------------------------------------------------------------------------- /mp78_streamlit_basics/roller_st_write.py: -------------------------------------------------------------------------------- 1 | from random import randint 2 | import streamlit as st 3 | 4 | roll = randint(1, 6) 5 | 6 | st.write(f"You rolled a {roll}.") -------------------------------------------------------------------------------- /mp130_door_codes/key_code_1_sequence.py: -------------------------------------------------------------------------------- 1 | from random import choices 2 | 3 | keycode = choices("0123456789", k=6) 4 | keycode = "".join(keycode) 5 | 6 | print(keycode) 7 | -------------------------------------------------------------------------------- /mp34_popular_projects/git-sim-merge_06-11-23_15-58-27.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ehmatthes/mostly_python/HEAD/mp34_popular_projects/git-sim-merge_06-11-23_15-58-27.jpg -------------------------------------------------------------------------------- /mp34_popular_projects/git-sim-merge_06-11-23_16-00-42.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ehmatthes/mostly_python/HEAD/mp34_popular_projects/git-sim-merge_06-11-23_16-00-42.mp4 -------------------------------------------------------------------------------- /mp89_breakpoint/subscriber_ids.csv: -------------------------------------------------------------------------------- 1 | email,subscriber_id 2 | mitchell_lewis@example.org,5eb63b 3 | nathan_smith@example.com,d4ab93 4 | megan_gardner@example.gov,1f9996 5 | -------------------------------------------------------------------------------- /mp20_list_gotchas/wild_cards.py: -------------------------------------------------------------------------------- 1 | hand = ['5♦', '4♣', 'w', '5♦', 'A♣', 'w', '3♥', 'w'] 2 | print(hand) 3 | 4 | while 'w' in hand: 5 | hand.remove('w') 6 | 7 | print(hand) -------------------------------------------------------------------------------- /mp89_breakpoint/subscribers.csv: -------------------------------------------------------------------------------- 1 | email,name 2 | mitchell_lewis@example.org,Mitchell Lewis 3 | nathan_smith@example.com,Nathan Smith 4 | megan_gardner@example.gov,Megan Gardner 5 | -------------------------------------------------------------------------------- /mp9_chatgpt_not_reliable_teacher/winners.py: -------------------------------------------------------------------------------- 1 | winners = ["elizabeth", "ryan", "kayla"] 2 | 3 | print("The winners are:") 4 | for winner in winners: 5 | print(winner.title()) -------------------------------------------------------------------------------- /mp24_grounding_part_3/tests/source_images/bear_scratching.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ehmatthes/mostly_python/HEAD/mp24_grounding_part_3/tests/source_images/bear_scratching.jpg -------------------------------------------------------------------------------- /mp26_grounding_part_4/tests/source_images/bear_scratching.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ehmatthes/mostly_python/HEAD/mp26_grounding_part_4/tests/source_images/bear_scratching.jpg -------------------------------------------------------------------------------- /mp33_using_pandas/output/high_temps_10_year_moving_average.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ehmatthes/mostly_python/HEAD/mp33_using_pandas/output/high_temps_10_year_moving_average.png -------------------------------------------------------------------------------- /mp33_using_pandas/output/high_temps_1_year_moving_average.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ehmatthes/mostly_python/HEAD/mp33_using_pandas/output/high_temps_1_year_moving_average.png -------------------------------------------------------------------------------- /mp33_using_pandas/output/high_temps_30_year_moving_average.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ehmatthes/mostly_python/HEAD/mp33_using_pandas/output/high_temps_30_year_moving_average.png -------------------------------------------------------------------------------- /mp33_using_pandas/output/high_temps_3_year_moving_average.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ehmatthes/mostly_python/HEAD/mp33_using_pandas/output/high_temps_3_year_moving_average.png -------------------------------------------------------------------------------- /mp33_using_pandas/output/high_temps_5_year_moving_average.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ehmatthes/mostly_python/HEAD/mp33_using_pandas/output/high_temps_5_year_moving_average.png -------------------------------------------------------------------------------- /mp47_oop8_comparison_methods/river.py: -------------------------------------------------------------------------------- 1 | class River: 2 | 3 | def __init__(self, name, length=0): 4 | self.name = name 5 | # Length in km. 6 | self.length = length -------------------------------------------------------------------------------- /mp85_calc_file_paths/coffee_reader_3_dunder_file.py: -------------------------------------------------------------------------------- 1 | from pathlib import Path 2 | 3 | path = Path(__file__).parent / "coffees.txt" 4 | contents = path.read_text() 5 | 6 | print(contents) -------------------------------------------------------------------------------- /mp89_breakpoint/generate_import_file.py: -------------------------------------------------------------------------------- 1 | from dataclasses import dataclass 2 | 3 | @dataclass 4 | class Member: 5 | email: str = "" 6 | member_id: str = "" 7 | name: str = "" -------------------------------------------------------------------------------- /mp128_checking_attributes/wx_model_wind.py: -------------------------------------------------------------------------------- 1 | from dataclasses import dataclass 2 | 3 | @dataclass 4 | class WeatherObservation: 5 | precip: float 6 | temp: float 7 | wind: float 8 | -------------------------------------------------------------------------------- /mp26_grounding_part_4/full_gpt_session_refactoring_add_border.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ehmatthes/mostly_python/HEAD/mp26_grounding_part_4/full_gpt_session_refactoring_add_border.png -------------------------------------------------------------------------------- /mp78_streamlit_basics/roller_button.py: -------------------------------------------------------------------------------- 1 | from random import randint 2 | import streamlit as st 3 | 4 | st.button("Roll") 5 | 6 | roll = randint(1, 6) 7 | 8 | st.write(f"You rolled a {roll}.") -------------------------------------------------------------------------------- /mp16_ending_while_loops/ten_squares_flag.py: -------------------------------------------------------------------------------- 1 | x = 1 2 | active = True 3 | while active: 4 | square = x**2 5 | print(square) 6 | 7 | x += 1 8 | if x > 10: 9 | active = False -------------------------------------------------------------------------------- /mp31_importance_profiling/output/high_temps_1_year_moving_average.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ehmatthes/mostly_python/HEAD/mp31_importance_profiling/output/high_temps_1_year_moving_average.png -------------------------------------------------------------------------------- /mp31_importance_profiling/output/high_temps_3_year_moving_average.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ehmatthes/mostly_python/HEAD/mp31_importance_profiling/output/high_temps_3_year_moving_average.png -------------------------------------------------------------------------------- /mp31_importance_profiling/output/high_temps_5_year_moving_average.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ehmatthes/mostly_python/HEAD/mp31_importance_profiling/output/high_temps_5_year_moving_average.png -------------------------------------------------------------------------------- /mp32_importance_profiling/output/high_temps_1_year_moving_average.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ehmatthes/mostly_python/HEAD/mp32_importance_profiling/output/high_temps_1_year_moving_average.png -------------------------------------------------------------------------------- /mp32_importance_profiling/output/high_temps_3_year_moving_average.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ehmatthes/mostly_python/HEAD/mp32_importance_profiling/output/high_temps_3_year_moving_average.png -------------------------------------------------------------------------------- /mp32_importance_profiling/output/high_temps_5_year_moving_average.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ehmatthes/mostly_python/HEAD/mp32_importance_profiling/output/high_temps_5_year_moving_average.png -------------------------------------------------------------------------------- /mp24_grounding_part_3/tests/reference_images/bear_scratching_default.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ehmatthes/mostly_python/HEAD/mp24_grounding_part_3/tests/reference_images/bear_scratching_default.jpg -------------------------------------------------------------------------------- /mp24_grounding_part_3/tests/source_images/bear_scratching_bordered.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ehmatthes/mostly_python/HEAD/mp24_grounding_part_3/tests/source_images/bear_scratching_bordered.jpg -------------------------------------------------------------------------------- /mp26_grounding_part_4/tests/reference_images/bear_scratching_default.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ehmatthes/mostly_python/HEAD/mp26_grounding_part_4/tests/reference_images/bear_scratching_default.jpg -------------------------------------------------------------------------------- /mp31_importance_profiling/output/high_temps_10_year_moving_average.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ehmatthes/mostly_python/HEAD/mp31_importance_profiling/output/high_temps_10_year_moving_average.png -------------------------------------------------------------------------------- /mp31_importance_profiling/output/high_temps_30_year_moving_average.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ehmatthes/mostly_python/HEAD/mp31_importance_profiling/output/high_temps_30_year_moving_average.png -------------------------------------------------------------------------------- /mp32_importance_profiling/output/high_temps_10_year_moving_average.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ehmatthes/mostly_python/HEAD/mp32_importance_profiling/output/high_temps_10_year_moving_average.png -------------------------------------------------------------------------------- /mp32_importance_profiling/output/high_temps_30_year_moving_average.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ehmatthes/mostly_python/HEAD/mp32_importance_profiling/output/high_temps_30_year_moving_average.png -------------------------------------------------------------------------------- /mp39_oop3_init/greeter.py: -------------------------------------------------------------------------------- 1 | class Greeter: 2 | """Greet people in a variety of ways.""" 3 | 4 | def say_hello(self): 5 | print("Hi.") 6 | 7 | greeter = Greeter() 8 | greeter.say_hello() -------------------------------------------------------------------------------- /mp58_urlspy_order/pianos/apps.py: -------------------------------------------------------------------------------- 1 | from django.apps import AppConfig 2 | 3 | 4 | class PianosConfig(AppConfig): 5 | default_auto_field = "django.db.models.BigAutoField" 6 | name = "pianos" 7 | -------------------------------------------------------------------------------- /mp58_urlspy_order/synths/apps.py: -------------------------------------------------------------------------------- 1 | from django.apps import AppConfig 2 | 3 | 4 | class SynthsConfig(AppConfig): 5 | default_auto_field = "django.db.models.BigAutoField" 6 | name = "synths" 7 | -------------------------------------------------------------------------------- /mp24_grounding_part_3/tests/reference_images/bear_scratching_15px_border.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ehmatthes/mostly_python/HEAD/mp24_grounding_part_3/tests/reference_images/bear_scratching_15px_border.jpg -------------------------------------------------------------------------------- /mp24_grounding_part_3/tests/reference_images/bear_scratching_15px_padding.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ehmatthes/mostly_python/HEAD/mp24_grounding_part_3/tests/reference_images/bear_scratching_15px_padding.jpg -------------------------------------------------------------------------------- /mp24_grounding_part_3/tests/reference_images/bear_scratching_black_border.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ehmatthes/mostly_python/HEAD/mp24_grounding_part_3/tests/reference_images/bear_scratching_black_border.jpg -------------------------------------------------------------------------------- /mp24_grounding_part_3/tests/source_images/bear_scratching_original_size.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ehmatthes/mostly_python/HEAD/mp24_grounding_part_3/tests/source_images/bear_scratching_original_size.jpg -------------------------------------------------------------------------------- /mp26_grounding_part_4/tests/reference_images/bear_scratching_15px_border.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ehmatthes/mostly_python/HEAD/mp26_grounding_part_4/tests/reference_images/bear_scratching_15px_border.jpg -------------------------------------------------------------------------------- /mp26_grounding_part_4/tests/reference_images/bear_scratching_15px_padding.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ehmatthes/mostly_python/HEAD/mp26_grounding_part_4/tests/reference_images/bear_scratching_15px_padding.jpg -------------------------------------------------------------------------------- /mp26_grounding_part_4/tests/reference_images/bear_scratching_black_border.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ehmatthes/mostly_python/HEAD/mp26_grounding_part_4/tests/reference_images/bear_scratching_black_border.jpg -------------------------------------------------------------------------------- /mp26_grounding_part_4/tests/source_images/bear_scratching_original_size.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ehmatthes/mostly_python/HEAD/mp26_grounding_part_4/tests/source_images/bear_scratching_original_size.jpg -------------------------------------------------------------------------------- /mp8_lists_closer_look_lists_tuples/primes_list.py: -------------------------------------------------------------------------------- 1 | primes = [2, 3, 5, 7, 11] 2 | primes_id = id(primes) 3 | print(primes_id, primes) 4 | 5 | primes.append(13) 6 | primes_id = id(primes) 7 | print(primes_id, primes) -------------------------------------------------------------------------------- /mp85_calc_file_paths/coffee_reader_2_absolute_path.py: -------------------------------------------------------------------------------- 1 | from pathlib import Path 2 | 3 | path = Path( 4 | "/Users/eric/projects/coffee_project/coffees.txt") 5 | contents = path.read_text() 6 | 7 | print(contents) -------------------------------------------------------------------------------- /mp24_grounding_part_3/partial_programs/tests_0/source_images/bear_scratching.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ehmatthes/mostly_python/HEAD/mp24_grounding_part_3/partial_programs/tests_0/source_images/bear_scratching.jpg -------------------------------------------------------------------------------- /mp24_grounding_part_3/partial_programs/tests_10/source_images/bear_scratching.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ehmatthes/mostly_python/HEAD/mp24_grounding_part_3/partial_programs/tests_10/source_images/bear_scratching.jpg -------------------------------------------------------------------------------- /mp24_grounding_part_3/partial_programs/tests_4/source_images/bear_scratching.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ehmatthes/mostly_python/HEAD/mp24_grounding_part_3/partial_programs/tests_4/source_images/bear_scratching.jpg -------------------------------------------------------------------------------- /mp26_grounding_part_4/partial_programs/tests_0/source_images/bear_scratching.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ehmatthes/mostly_python/HEAD/mp26_grounding_part_4/partial_programs/tests_0/source_images/bear_scratching.jpg -------------------------------------------------------------------------------- /mp26_grounding_part_4/partial_programs/tests_2/source_images/bear_scratching.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ehmatthes/mostly_python/HEAD/mp26_grounding_part_4/partial_programs/tests_2/source_images/bear_scratching.jpg -------------------------------------------------------------------------------- /mp26_grounding_part_4/partial_programs/tests_4/source_images/bear_scratching.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ehmatthes/mostly_python/HEAD/mp26_grounding_part_4/partial_programs/tests_4/source_images/bear_scratching.jpg -------------------------------------------------------------------------------- /mp55_oop13_serialization_abc/robot_dict.py: -------------------------------------------------------------------------------- 1 | from pathlib import Path 2 | import json 3 | 4 | robot = {'name': 'Marvin'} 5 | 6 | robot_data = json.dumps(robot) 7 | path = Path("robot.json") 8 | path.write_text(robot_data) -------------------------------------------------------------------------------- /mp8_lists_closer_look_lists_tuples/primes_tuple.py: -------------------------------------------------------------------------------- 1 | primes = (2, 3, 5, 7, 11) 2 | primes_id = id(primes) 3 | print(primes_id, primes) 4 | 5 | primes = (2, 3, 5, 7, 11, 13) 6 | primes_id = id(primes) 7 | print(primes_id, primes) -------------------------------------------------------------------------------- /mp6_searching_quick_answers/my_great_ide.py: -------------------------------------------------------------------------------- 1 | lines = [ 2 | '"""A simple Hello World program."""', 3 | "", 4 | 'msg = "Hello Python world!"', 5 | 'print(msg)' 6 | ] 7 | 8 | for line in lines: 9 | print(line) -------------------------------------------------------------------------------- /mp85_calc_file_paths/coffee_reader_4_project_root.py: -------------------------------------------------------------------------------- 1 | from pathlib import Path 2 | 3 | project_root = Path(__file__).parent 4 | path = project_root / "coffees" / "coffees.txt" 5 | contents = path.read_text() 6 | 7 | print(contents) -------------------------------------------------------------------------------- /mp24_grounding_part_3/tests/reference_images/bear_scratching_20px_border_15px_padding.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ehmatthes/mostly_python/HEAD/mp24_grounding_part_3/tests/reference_images/bear_scratching_20px_border_15px_padding.jpg -------------------------------------------------------------------------------- /mp26_grounding_part_4/tests/reference_images/bear_scratching_20px_border_15px_padding.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ehmatthes/mostly_python/HEAD/mp26_grounding_part_4/tests/reference_images/bear_scratching_20px_border_15px_padding.jpg -------------------------------------------------------------------------------- /mp24_grounding_part_3/partial_programs/tests_10/reference_images/bear_scratching_default.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ehmatthes/mostly_python/HEAD/mp24_grounding_part_3/partial_programs/tests_10/reference_images/bear_scratching_default.jpg -------------------------------------------------------------------------------- /mp26_grounding_part_4/partial_programs/tests_0/reference_images/bear_scratching_default.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ehmatthes/mostly_python/HEAD/mp26_grounding_part_4/partial_programs/tests_0/reference_images/bear_scratching_default.jpg -------------------------------------------------------------------------------- /mp26_grounding_part_4/partial_programs/tests_2/reference_images/bear_scratching_default.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ehmatthes/mostly_python/HEAD/mp26_grounding_part_4/partial_programs/tests_2/reference_images/bear_scratching_default.jpg -------------------------------------------------------------------------------- /mp26_grounding_part_4/partial_programs/tests_4/reference_images/bear_scratching_default.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ehmatthes/mostly_python/HEAD/mp26_grounding_part_4/partial_programs/tests_4/reference_images/bear_scratching_default.jpg -------------------------------------------------------------------------------- /mp57_exception_hierarchy/bad_list_2_help.py: -------------------------------------------------------------------------------- 1 | python_exceptions = [ 2 | "SyntaxError", 3 | "NameError", 4 | ] 5 | 6 | try: 7 | my_exception = python_exceptions[2] 8 | except IndexError as e: 9 | help(e) 10 | raise e -------------------------------------------------------------------------------- /mp9_chatgpt_not_reliable_teacher/winners_ranked.py: -------------------------------------------------------------------------------- 1 | winners = ["elizabeth", "ryan", "kayla"] 2 | 3 | print("The winners are:") 4 | for index, winner in enumerate(winners): 5 | place = index + 1 6 | print(f"{place}. {winner.title()}") -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | __pycache__/ 2 | *.pyc 3 | 4 | .DS_Store 5 | 6 | .venv/ 7 | 8 | .ipynb_checkpoints/ 9 | 10 | git-sim_media/ 11 | 12 | # Files associated with specific posts. 13 | mp23_grounding_part_2/willie_mountains_bordered.png 14 | -------------------------------------------------------------------------------- /mp24_grounding_part_3/partial_programs/tests_10/reference_images/bear_scratching_15px_border.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ehmatthes/mostly_python/HEAD/mp24_grounding_part_3/partial_programs/tests_10/reference_images/bear_scratching_15px_border.jpg -------------------------------------------------------------------------------- /mp24_grounding_part_3/partial_programs/tests_10/reference_images/bear_scratching_15px_padding.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ehmatthes/mostly_python/HEAD/mp24_grounding_part_3/partial_programs/tests_10/reference_images/bear_scratching_15px_padding.jpg -------------------------------------------------------------------------------- /mp24_grounding_part_3/partial_programs/tests_10/reference_images/bear_scratching_black_border.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ehmatthes/mostly_python/HEAD/mp24_grounding_part_3/partial_programs/tests_10/reference_images/bear_scratching_black_border.jpg -------------------------------------------------------------------------------- /mp24_grounding_part_3/partial_programs/tests_10/source_images/bear_scratching_original_size.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ehmatthes/mostly_python/HEAD/mp24_grounding_part_3/partial_programs/tests_10/source_images/bear_scratching_original_size.jpg -------------------------------------------------------------------------------- /mp26_grounding_part_4/partial_programs/tests_0/reference_images/bear_scratching_15px_border.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ehmatthes/mostly_python/HEAD/mp26_grounding_part_4/partial_programs/tests_0/reference_images/bear_scratching_15px_border.jpg -------------------------------------------------------------------------------- /mp26_grounding_part_4/partial_programs/tests_0/reference_images/bear_scratching_15px_padding.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ehmatthes/mostly_python/HEAD/mp26_grounding_part_4/partial_programs/tests_0/reference_images/bear_scratching_15px_padding.jpg -------------------------------------------------------------------------------- /mp26_grounding_part_4/partial_programs/tests_0/reference_images/bear_scratching_black_border.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ehmatthes/mostly_python/HEAD/mp26_grounding_part_4/partial_programs/tests_0/reference_images/bear_scratching_black_border.jpg -------------------------------------------------------------------------------- /mp26_grounding_part_4/partial_programs/tests_2/reference_images/bear_scratching_15px_border.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ehmatthes/mostly_python/HEAD/mp26_grounding_part_4/partial_programs/tests_2/reference_images/bear_scratching_15px_border.jpg -------------------------------------------------------------------------------- /mp26_grounding_part_4/partial_programs/tests_2/reference_images/bear_scratching_15px_padding.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ehmatthes/mostly_python/HEAD/mp26_grounding_part_4/partial_programs/tests_2/reference_images/bear_scratching_15px_padding.jpg -------------------------------------------------------------------------------- /mp26_grounding_part_4/partial_programs/tests_2/reference_images/bear_scratching_black_border.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ehmatthes/mostly_python/HEAD/mp26_grounding_part_4/partial_programs/tests_2/reference_images/bear_scratching_black_border.jpg -------------------------------------------------------------------------------- /mp26_grounding_part_4/partial_programs/tests_4/reference_images/bear_scratching_15px_border.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ehmatthes/mostly_python/HEAD/mp26_grounding_part_4/partial_programs/tests_4/reference_images/bear_scratching_15px_border.jpg -------------------------------------------------------------------------------- /mp26_grounding_part_4/partial_programs/tests_4/reference_images/bear_scratching_15px_padding.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ehmatthes/mostly_python/HEAD/mp26_grounding_part_4/partial_programs/tests_4/reference_images/bear_scratching_15px_padding.jpg -------------------------------------------------------------------------------- /mp26_grounding_part_4/partial_programs/tests_4/reference_images/bear_scratching_black_border.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ehmatthes/mostly_python/HEAD/mp26_grounding_part_4/partial_programs/tests_4/reference_images/bear_scratching_black_border.jpg -------------------------------------------------------------------------------- /mp37_oop2_self/squares.py: -------------------------------------------------------------------------------- 1 | import matplotlib.pyplot as plt 2 | 3 | x_vals = list(range(100)) 4 | squares = [x**2 for x in x_vals] 5 | 6 | plt.style.use('classic') 7 | fig, ax = plt.subplots() 8 | ax.scatter(x_vals, squares) 9 | 10 | plt.show() -------------------------------------------------------------------------------- /mp57_exception_hierarchy/bad_list_5_mro.py: -------------------------------------------------------------------------------- 1 | python_exceptions = [ 2 | "SyntaxError", 3 | "NameError", 4 | ] 5 | 6 | try: 7 | my_exception = python_exceptions[2] 8 | except LookupError as e: 9 | print(type(e).mro()) 10 | raise e -------------------------------------------------------------------------------- /mp97_snippets/raw_snippets/plot_data.py: -------------------------------------------------------------------------------- 1 | for reading_set in reading_sets: 2 | ph.plot_data_static( 3 | reading_set, 4 | known_slides=known_slides, 5 | critical_points=critical_points 6 | ) 7 | 8 | a_utils.summarize_results() -------------------------------------------------------------------------------- /mp24_grounding_part_3/partial_programs/tests_0/reference_images/bear_scratching_bordered_default.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ehmatthes/mostly_python/HEAD/mp24_grounding_part_3/partial_programs/tests_0/reference_images/bear_scratching_bordered_default.jpg -------------------------------------------------------------------------------- /mp24_grounding_part_3/partial_programs/tests_4/reference_images/bear_scratching_bordered_default.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ehmatthes/mostly_python/HEAD/mp24_grounding_part_3/partial_programs/tests_4/reference_images/bear_scratching_bordered_default.jpg -------------------------------------------------------------------------------- /mp57_exception_hierarchy/bad_list_4_catch_lookuperror.py: -------------------------------------------------------------------------------- 1 | python_exceptions = [ 2 | "SyntaxError", 3 | "NameError", 4 | ] 5 | 6 | try: 7 | my_exception = python_exceptions[2] 8 | except LookupError as e: 9 | print(type(e)) 10 | raise e -------------------------------------------------------------------------------- /mp49_oop9_helper_methods/chessboard.py: -------------------------------------------------------------------------------- 1 | class ChessBoard: 2 | 3 | def __init__(self): 4 | self.position = "RNBQKBNR" 5 | 6 | def show_position(self): 7 | print(self.position) 8 | 9 | board = ChessBoard() 10 | board.show_position() -------------------------------------------------------------------------------- /mp128_checking_attributes/wx_reporter.py: -------------------------------------------------------------------------------- 1 | import wx_observer 2 | 3 | def show_summary(obs): 4 | print("\nObservation summary:") 5 | print(f" Precipitation: {obs.precip}cm") 6 | print(f" Temp: {obs.temp}C") 7 | 8 | show_summary(wx_observer.wx_obs) -------------------------------------------------------------------------------- /mp13_lists_sets/explore_responses.py: -------------------------------------------------------------------------------- 1 | from pathlib import Path 2 | import json 3 | 4 | path = Path('responses.json') 5 | contents = path.read_text() 6 | responses = json.loads(contents) 7 | 8 | num_responses = len(responses) 9 | print(f"Found {num_responses:,} responses.") -------------------------------------------------------------------------------- /mp24_grounding_part_3/partial_programs/tests_10/reference_images/bear_scratching_20px_border_15px_padding.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ehmatthes/mostly_python/HEAD/mp24_grounding_part_3/partial_programs/tests_10/reference_images/bear_scratching_20px_border_15px_padding.jpg -------------------------------------------------------------------------------- /mp26_grounding_part_4/partial_programs/tests_0/reference_images/bear_scratching_20px_border_15px_padding.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ehmatthes/mostly_python/HEAD/mp26_grounding_part_4/partial_programs/tests_0/reference_images/bear_scratching_20px_border_15px_padding.jpg -------------------------------------------------------------------------------- /mp26_grounding_part_4/partial_programs/tests_2/reference_images/bear_scratching_20px_border_15px_padding.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ehmatthes/mostly_python/HEAD/mp26_grounding_part_4/partial_programs/tests_2/reference_images/bear_scratching_20px_border_15px_padding.jpg -------------------------------------------------------------------------------- /mp26_grounding_part_4/partial_programs/tests_4/reference_images/bear_scratching_20px_border_15px_padding.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ehmatthes/mostly_python/HEAD/mp26_grounding_part_4/partial_programs/tests_4/reference_images/bear_scratching_20px_border_15px_padding.jpg -------------------------------------------------------------------------------- /mp57_exception_hierarchy/bad_list_3_isinstance.py: -------------------------------------------------------------------------------- 1 | python_exceptions = [ 2 | "SyntaxError", 3 | "NameError", 4 | ] 5 | 6 | try: 7 | my_exception = python_exceptions[2] 8 | except IndexError as e: 9 | print(isinstance(e, LookupError)) 10 | raise e -------------------------------------------------------------------------------- /mp9_chatgpt_not_reliable_teacher/winners_bizarre_chatgpt_loop.py: -------------------------------------------------------------------------------- 1 | winners = ["elizabeth", "ryan", "kayla"] 2 | 3 | print("The winners are:") 4 | for i, winner in [(i, winner) for i, winner in enumerate(winners)]: 5 | place = i + 1 6 | print(f"{place}. {winner.title()}") -------------------------------------------------------------------------------- /mp20_list_gotchas/card_game_one_player.py: -------------------------------------------------------------------------------- 1 | from player import Player 2 | from dealer import get_card 3 | 4 | eric = Player('Eric') 5 | eric.show_cards() 6 | 7 | for _ in range(5): 8 | new_card = get_card() 9 | eric.hand.append(new_card) 10 | 11 | eric.show_cards() -------------------------------------------------------------------------------- /mp24_grounding_part_3/partial_programs/tests_0/reference_images/bear_scratching_bordered_default_15px_border.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ehmatthes/mostly_python/HEAD/mp24_grounding_part_3/partial_programs/tests_0/reference_images/bear_scratching_bordered_default_15px_border.jpg -------------------------------------------------------------------------------- /mp24_grounding_part_3/partial_programs/tests_4/reference_images/bear_scratching_bordered_default_15px_border.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ehmatthes/mostly_python/HEAD/mp24_grounding_part_3/partial_programs/tests_4/reference_images/bear_scratching_bordered_default_15px_border.jpg -------------------------------------------------------------------------------- /mp2_lists_closer_look/bookshelf.py: -------------------------------------------------------------------------------- 1 | books = [ 2 | "Python Crash Course", 3 | "Serious Python", 4 | "Fluent Python", 5 | "Mastering Regular Expressions", 6 | "Fundamentals of Data Visualization", 7 | ] 8 | 9 | for book in books: 10 | print(book) 11 | -------------------------------------------------------------------------------- /mp37_oop2_self/robot.py: -------------------------------------------------------------------------------- 1 | class Robot: 2 | """A class representing simple robots.""" 3 | 4 | def __init__(self, name=""): 5 | self.name = name 6 | 7 | def say_hello(self): 8 | print(f"Hi, I'm {self.name}!") 9 | 10 | my_robot = Robot("William") -------------------------------------------------------------------------------- /mp15_lists_arguments/generate_requests.py: -------------------------------------------------------------------------------- 1 | from random import choice 2 | 3 | requests = [] 4 | for r_num in range(12): 5 | request = f"request_{r_num}" 6 | if choice([True, False]): 7 | request += "_bad" 8 | requests.append(request) 9 | 10 | print(requests) -------------------------------------------------------------------------------- /mp58_urlspy_order/synths/urls.py: -------------------------------------------------------------------------------- 1 | """URL patterns for synths.""" 2 | 3 | from django.urls import path 4 | from . import views 5 | 6 | app_name = 'synths' 7 | urlpatterns = [ 8 | path('about/', views.about, name='about'), 9 | path('faq/', views.faq, name='faq'), 10 | ] -------------------------------------------------------------------------------- /mp130_door_codes/key_code_2_cli.py: -------------------------------------------------------------------------------- 1 | from random import choices 2 | import sys 3 | 4 | try: 5 | length = int(sys.argv[1]) 6 | except IndexError: 7 | length = 6 8 | 9 | keycode = choices("0123456789", k=length) 10 | keycode = "".join(keycode) 11 | 12 | print(keycode) 13 | -------------------------------------------------------------------------------- /mp46_oop7_new/nonzero_list.py: -------------------------------------------------------------------------------- 1 | class NonZeroList(list): 2 | 3 | def __init__(self, values): 4 | """Only keep nonzero values.""" 5 | values = [v for v in values if v] 6 | super().__init__(values) 7 | 8 | my_list = NonZeroList((1, 2, 0, 3, 5, 0)) 9 | print(my_list) -------------------------------------------------------------------------------- /mp47_oop8_comparison_methods/river_2_greater_than.py: -------------------------------------------------------------------------------- 1 | class River: 2 | 3 | def __init__(self, name, length=0): 4 | self.name = name 5 | # Length in km. 6 | self.length = length 7 | 8 | def __gt__(self, river_2): 9 | return self.length > river_2.length -------------------------------------------------------------------------------- /mp46_oop7_new/nonzero_tuple.py: -------------------------------------------------------------------------------- 1 | class NonZeroTuple(tuple): 2 | 3 | def __init__(self, values): 4 | """Only keep nonzero values.""" 5 | values = [v for v in values if v] 6 | super().__init__(values) 7 | 8 | my_tuple = NonZeroTuple((1, 2, 0, 3, 5, 0)) 9 | print(my_tuple) -------------------------------------------------------------------------------- /mp46_oop7_new/nonzero_tuple_2.py: -------------------------------------------------------------------------------- 1 | class NonZeroTuple(tuple): 2 | 3 | def __new__(cls, *values): 4 | """Only keep nonzero values.""" 5 | values = [v for v in values if v] 6 | return super().__new__(cls, values) 7 | 8 | my_tuple = NonZeroTuple(1, 2, 0, 3, 5, 0) 9 | print(my_tuple) -------------------------------------------------------------------------------- /mp65_october_wx/october_temps.py: -------------------------------------------------------------------------------- 1 | from pathlib import Path 2 | import pandas as pd 3 | 4 | path = Path('wx_data/sitka_temps_1983_2023.csv') 5 | df = pd.read_csv(path) 6 | df['DATE'] = pd.to_datetime(df['DATE']) 7 | 8 | dates = df['DATE'] 9 | highs = df['TMAX'] 10 | 11 | print(dates[:5], highs[:5]) -------------------------------------------------------------------------------- /mp6_searching_quick_answers/my_great_ide_index.py: -------------------------------------------------------------------------------- 1 | lines = [ 2 | '"""A simple Hello World program."""', 3 | "", 4 | 'msg = "Hello Python world!"', 5 | 'print(msg)' 6 | ] 7 | 8 | for i in range(len(lines)): 9 | line_num = i + 1 10 | print(f"{line_num}\t{lines[i]}") -------------------------------------------------------------------------------- /mp78_streamlit_basics/roller_radio.py: -------------------------------------------------------------------------------- 1 | from random import randint 2 | import streamlit as st 3 | 4 | side_options = [6, 10, 12, 20] 5 | num_sides = st.radio("Number of sides:", side_options) 6 | 7 | st.button("Roll") 8 | 9 | roll = randint(1, num_sides) 10 | 11 | st.write(f"You rolled a {roll}.") -------------------------------------------------------------------------------- /mp37_oop2_self/squares_dict.py: -------------------------------------------------------------------------------- 1 | import matplotlib.pyplot as plt 2 | 3 | x_vals = list(range(100)) 4 | squares = [x**2 for x in x_vals] 5 | 6 | plt.style.use('classic') 7 | fig, ax = plt.subplots() 8 | ax.scatter(x_vals, squares) 9 | 10 | plt.show() 11 | 12 | print(type(ax)) 13 | print(ax.__dict__) -------------------------------------------------------------------------------- /mp37_oop2_self/robot_print_self.py: -------------------------------------------------------------------------------- 1 | class Robot: 2 | """A class representing simple robots.""" 3 | 4 | def __init__(self, name=""): 5 | self.name = name 6 | print(self) 7 | 8 | def say_hello(self): 9 | print(f"Hi, I'm {self.name}!") 10 | 11 | my_robot = Robot("William") -------------------------------------------------------------------------------- /mp6_searching_quick_answers/my_great_ide_enumerate.py: -------------------------------------------------------------------------------- 1 | lines = [ 2 | '"""A simple Hello World program."""', 3 | "", 4 | 'msg = "Hello Python world!"', 5 | 'print(msg)' 6 | ] 7 | 8 | for index, line in enumerate(lines): 9 | line_num = index + 1 10 | print(f"{line_num}\t{line}") -------------------------------------------------------------------------------- /mp19_improving_code_blocks/partial_programs/email_parser_1.py: -------------------------------------------------------------------------------- 1 | """Parse raw post data, and generate neatly formatted 2 | code block titles. 3 | """ 4 | 5 | from pathlib import Path 6 | 7 | # Read post file and template file. 8 | post = Path('raw_post.html').read_text() 9 | template = Path('my_template.eml').read_text() -------------------------------------------------------------------------------- /mp29_settings/small_examples.py: -------------------------------------------------------------------------------- 1 | x = 5 2 | y = x 3 | x += 1 4 | 5 | print(f'{x = }') 6 | print(f'{y = }') 7 | 8 | x = 'Hello' 9 | y = x 10 | x += ' everyone!' 11 | 12 | print(f'{x = }') 13 | print(f'{y = }') 14 | 15 | x = [1, 2, 3] 16 | y = x 17 | x.append(4) 18 | 19 | print(f'{x = }') 20 | print(f'{y = }') -------------------------------------------------------------------------------- /mp37_oop2_self/robot_army.py: -------------------------------------------------------------------------------- 1 | class Robot: 2 | """A class representing simple robots.""" 3 | 4 | def __init__(self, name=""): 5 | self.name = name 6 | print(self) 7 | 8 | def say_hello(self): 9 | print(f"Hi, I'm {self.name}!") 10 | 11 | my_army = [Robot() for _ in range(3)] -------------------------------------------------------------------------------- /mp37_oop2_self/robot_potato.py: -------------------------------------------------------------------------------- 1 | class Robot: 2 | """A class representing simple robots.""" 3 | 4 | def __init__(potato, name=""): 5 | potato.name = name 6 | 7 | def say_hello(potato): 8 | print(f"Hi, I'm {potato.name}!") 9 | 10 | my_robot = Robot("William") 11 | my_robot.say_hello() -------------------------------------------------------------------------------- /mp126_function_checklist/fn_checklist_0_parse_file.py: -------------------------------------------------------------------------------- 1 | from pathlib import Path 2 | 3 | path = Path(__file__).parent / "deploy.py" 4 | 5 | # Get all lines with a function definition. 6 | lines = [ 7 | line 8 | for line in path.read_text().splitlines() 9 | if ' def ' in line 10 | ] 11 | 12 | breakpoint() -------------------------------------------------------------------------------- /mp29_settings/alien.py: -------------------------------------------------------------------------------- 1 | class Alien: 2 | 3 | def __init__(self, game): 4 | self.settings = game.settings 5 | 6 | def show_settings(self): 7 | print("\nIn Alien:") 8 | print(f" alien speed: {self.settings['alien_speed']}") 9 | print(f" alien direction: {self.settings['alien_direction']}") -------------------------------------------------------------------------------- /mp124_real_estate_images/image_archiver_0_naive.py: -------------------------------------------------------------------------------- 1 | from pathlib import Path 2 | import httpx 3 | 4 | url = "https://www.zillow.com/homedetails/" 5 | url += "432-Park-Ave-PENTHOUSE-New-York-NY-10022/2069500049_zpid/" 6 | r = httpx.get(url) 7 | 8 | path = Path(__file__).parent / "output_file.html" 9 | path.write_text(r.text) 10 | -------------------------------------------------------------------------------- /mp126_function_checklist/fn_checklist_1_no_comprehension.py: -------------------------------------------------------------------------------- 1 | from pathlib import Path 2 | 3 | path = Path(__file__).parent / "deploy.py" 4 | 5 | # Get all lines with a function definition. 6 | lines = [] 7 | for line in path.read_text().splitlines(): 8 | if ' def ' in line: 9 | lines.append(line) 10 | 11 | breakpoint() -------------------------------------------------------------------------------- /mp37_oop2_self/robot_print_self_2.py: -------------------------------------------------------------------------------- 1 | class Robot: 2 | """A class representing simple robots.""" 3 | 4 | def __init__(self, name=""): 5 | self.name = name 6 | print(self) 7 | 8 | def say_hello(self): 9 | print(f"Hi, I'm {self.name}!") 10 | 11 | my_robot = Robot("William") 12 | print(my_robot) -------------------------------------------------------------------------------- /mp20_list_gotchas/dealer.py: -------------------------------------------------------------------------------- 1 | from random import choice 2 | 3 | def get_card(): 4 | """Return a random card.""" 5 | suits = ('\u2660', '\u2663', '\u2665', '\u2666') 6 | values = ( 7 | '2', '3', '4', '5', '6', '7', '8', '9', '10', 8 | 'J', 'Q', 'K', 'A' 9 | ) 10 | return choice(values) + choice(suits) -------------------------------------------------------------------------------- /mp58_urlspy_order/piano_store/urls.py: -------------------------------------------------------------------------------- 1 | """URL configuration for piano_store project.""" 2 | 3 | from django.contrib import admin 4 | from django.urls import path, include 5 | 6 | urlpatterns = [ 7 | path('admin/', admin.site.urls), 8 | path('', include('pianos.urls')), 9 | path('synths/', include('synths.urls')), 10 | ] 11 | -------------------------------------------------------------------------------- /mp89_breakpoint/generate_import_file_2_read_csv.py: -------------------------------------------------------------------------------- 1 | from dataclasses import dataclass 2 | from pathlib import Path 3 | 4 | import pandas as pd 5 | 6 | @dataclass 7 | class Member: 8 | email: str = "" 9 | member_id: str = "" 10 | name: str = "" 11 | 12 | path = Path("subscribers.csv") 13 | subscriber_data = pd.read_csv(path) -------------------------------------------------------------------------------- /mp19_improving_code_blocks/raw_post_without_title.html: -------------------------------------------------------------------------------- 1 |
Here's a simple code block:
2 |message = "Hello newsletter world!"
3 | print(message)
4 |
5 | message = "This could really be formatted better. :/"
6 | print(message)
7 | It would be nice to separate the filename from the code, and add some line numbers.
-------------------------------------------------------------------------------- /mp20_list_gotchas/fixed/dealer.py: -------------------------------------------------------------------------------- 1 | from random import choice 2 | 3 | def get_card(): 4 | """Return a random card.""" 5 | suits = ('\u2660', '\u2663', '\u2665', '\u2666') 6 | values = ( 7 | '2', '3', '4', '5', '6', '7', '8', '9', '10', 8 | 'J', 'Q', 'K', 'A' 9 | ) 10 | return choice(values) + choice(suits) -------------------------------------------------------------------------------- /mp24_grounding_part_3/add_border.py: -------------------------------------------------------------------------------- 1 | """Add a border to any image.""" 2 | 3 | from cli import process_cli_args 4 | import image_functions as img_fns 5 | 6 | 7 | # Process image. 8 | path, options = process_cli_args() 9 | img = img_fns.load_image(path) 10 | new_img = img_fns.process_image(img, options) 11 | img_fns.save_image(path, new_img) -------------------------------------------------------------------------------- /mp29_settings/partial_programs/alien_3.py: -------------------------------------------------------------------------------- 1 | class Alien: 2 | 3 | def __init__(self, game): 4 | self.settings = game.settings 5 | 6 | def show_settings(self): 7 | print("\nIn Alien:") 8 | print(f" alien speed: {self.settings['alien_speed']}") 9 | print(f" alien direction: {self.settings['alien_direction']}") -------------------------------------------------------------------------------- /mp12_lists_arrays/best_sequence.py: -------------------------------------------------------------------------------- 1 | import random 2 | 3 | def get_flips(num_flips=10): 4 | """Return a random sequence of coin flips.""" 5 | outcomes = ('H', 'T') 6 | return random.choices(outcomes, k=num_flips) 7 | 8 | # Generate flips. 9 | all_flips = get_flips() 10 | print(f"Generated {len(all_flips):,} flips.") 11 | print(all_flips) -------------------------------------------------------------------------------- /mp19_improving_code_blocks/raw_post.html: -------------------------------------------------------------------------------- 1 |Here's a simple code block:
2 |### title="hello.py"
3 | message = "Hello newsletter world!"
4 | print(message)
5 |
6 | message = "This could really be formatted better. :/"
7 | print(message)
8 | It would be nice to separate the filename from the code, and add some line numbers.
-------------------------------------------------------------------------------- /mp44_oop6_str_repr/bonsai.py: -------------------------------------------------------------------------------- 1 | class BonsaiTree: 2 | 3 | def __init__(self, name, description=""): 4 | self.name = name 5 | self.description = description 6 | 7 | def describe_tree(self): 8 | msg = f"{self.name}: {self.description}" 9 | print(msg) 10 | 11 | tree = BonsaiTree("Winged Elm") 12 | print(tree) 13 | -------------------------------------------------------------------------------- /mp46_oop7_new/nonzero_list_2.py: -------------------------------------------------------------------------------- 1 | class NonZeroList(list): 2 | 3 | def __init__(self, values): 4 | """Only keep nonzero values.""" 5 | values = [v for v in values if v] 6 | super().__init__(values) 7 | 8 | my_list = NonZeroList((1, 2, 0, 3, 5, 0)) 9 | print(my_list) 10 | 11 | print(type(my_list)) 12 | help(my_list) 13 | -------------------------------------------------------------------------------- /mp58_urlspy_order/synths/views.py: -------------------------------------------------------------------------------- 1 | from django.http import HttpResponse 2 | 3 | def about(request): 4 | for pattern in request.resolver_match.tried: 5 | print(pattern) 6 | 7 | msg = "About our synths" 8 | return HttpResponse(msg) 9 | 10 | def faq(request): 11 | msg = "Synthesizer FAQ" 12 | return HttpResponse(msg) -------------------------------------------------------------------------------- /mp10_lists_profiling/sum_squares_optimize_get_sum.py: -------------------------------------------------------------------------------- 1 | def get_squares(): 2 | """Return a list of square numbers.""" 3 | return [x**2 for x in range(50_000_000)] 4 | 5 | def get_sum(squares): 6 | """Return the sum of all squares.""" 7 | return sum(squares) 8 | 9 | squares = get_squares() 10 | sum = get_sum(squares) 11 | print(f"Sum: {sum:,}") -------------------------------------------------------------------------------- /mp24_grounding_part_3/partial_programs/add_border_11.py: -------------------------------------------------------------------------------- 1 | """Add a border to any image.""" 2 | 3 | from cli import process_cli_args 4 | import image_functions as img_fns 5 | 6 | 7 | # Process image. 8 | path, options = process_cli_args() 9 | img = img_fns.load_image(path) 10 | new_img = img_fns.process_image(img, options) 11 | img_fns.save_image(path, new_img) -------------------------------------------------------------------------------- /mp29_settings/partial_programs/alien_1.py: -------------------------------------------------------------------------------- 1 | class Alien: 2 | 3 | def __init__(self, game): 4 | self.speed = game.alien_speed 5 | self.direction = game.alien_direction 6 | 7 | def show_settings(self): 8 | print("\nIn Alien:") 9 | print(f" alien speed: {self.speed}") 10 | print(f" alien direction: {self.direction}") -------------------------------------------------------------------------------- /mp19_improving_code_blocks/highlighting_lines/raw_post.html: -------------------------------------------------------------------------------- 1 |Here's a simple code block:
2 |### hl_lines="3,4"
3 | message = "Hello newsletter world!"
4 | print(message)
5 |
6 | message = "This could really be formatted better. :/"
7 | print(message)
8 | It would be nice to separate the filename from the code, and add some line numbers.
-------------------------------------------------------------------------------- /mp130_door_codes/key_code_3_repeated_digits.py: -------------------------------------------------------------------------------- 1 | from random import choices 2 | import sys 3 | 4 | try: 5 | length = int(sys.argv[1]) 6 | except IndexError: 7 | length = 6 8 | 9 | while True: 10 | keycode = choices("0123456789", k=length) 11 | if len(set(keycode)) == length - 1: 12 | break 13 | 14 | keycode = "".join(keycode) 15 | print(keycode) 16 | -------------------------------------------------------------------------------- /mp143_debugging_4/tests/e2e_tests/conftest.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | import pytest 4 | 5 | 6 | # --- Fixtures --- 7 | 8 | 9 | @pytest.fixture(autouse=True, scope="session") 10 | def set_random_seed_env(): 11 | """Make random selections repeatable.""" 12 | # To verify a random action, set autouse to False and run one test. 13 | os.environ["DICE_BATTLE_RANDOM_SEED"] = "10" -------------------------------------------------------------------------------- /mp58_urlspy_order/pianos/urls.py: -------------------------------------------------------------------------------- 1 | """URL patterns for pianos.""" 2 | 3 | from django.urls import path 4 | from . import views 5 | 6 | app_name = 'pianos' 7 | urlpatterns = [ 8 | path('', views.index, name='index'), 9 | path('about/', views.about, name='about'), 10 | path('contact/', views.contact, name='contact'), 11 | path('faq/', views.faq, name='faq'), 12 | ] -------------------------------------------------------------------------------- /mp37_oop2_self/robot_print_self_3.py: -------------------------------------------------------------------------------- 1 | class Robot: 2 | """A class representing simple robots.""" 3 | 4 | def __init__(self, name=""): 5 | self.name = name 6 | print(self) 7 | 8 | def say_hello(self): 9 | print(f"Hi, I'm {self.name}!") 10 | print(self) 11 | 12 | my_robot = Robot("William") 13 | print(my_robot) 14 | 15 | my_robot.say_hello() -------------------------------------------------------------------------------- /mp89_breakpoint/generate_import_file_3_breakpoint.py: -------------------------------------------------------------------------------- 1 | from dataclasses import dataclass 2 | from pathlib import Path 3 | import pdb 4 | 5 | import pandas as pd 6 | 7 | @dataclass 8 | class Member: 9 | email: str = "" 10 | member_id: str = "" 11 | name: str = "" 12 | 13 | path = Path("subscribers.csv") 14 | subscriber_data = pd.read_csv(path) 15 | 16 | breakpoint() 17 | -------------------------------------------------------------------------------- /mp42_oop5_class_methods/trees.py: -------------------------------------------------------------------------------- 1 | class BonsaiTree: 2 | 3 | def __init__(self, name, description=""): 4 | self.name = name 5 | self.description = description 6 | 7 | def describe_tree(self): 8 | msg = f"{self.name}: {self.description}" 9 | print(msg) 10 | 11 | tree = BonsaiTree("Winged Elm") 12 | tree.description = "tall, solid trunk" 13 | tree.describe_tree() -------------------------------------------------------------------------------- /mp41_static_methods/mountains.py: -------------------------------------------------------------------------------- 1 | class Mountain: 2 | 3 | def __init__(self, name="", elev_meters=0): 4 | self.name = name 5 | self.elev_meters = elev_meters 6 | 7 | def describe_mountain(self): 8 | msg = f"{self.name} is {self.elev_meters:,} meters tall." 9 | print(msg) 10 | 11 | my_mountain = Mountain("Mt. Verstovia", 1022) 12 | my_mountain.describe_mountain() -------------------------------------------------------------------------------- /mp148_min_rep_example/rolling_dice/die.py: -------------------------------------------------------------------------------- 1 | from random import randint 2 | 3 | class Die: 4 | """A class representing a single die.""" 5 | 6 | def __init__(self, num_sides=6): 7 | """Assume a six-sided die.""" 8 | self.num_sides = num_sides 9 | 10 | def roll(self): 11 | """"Return a random value between 1 and number of sides.""" 12 | return randint(1, self.num_sides) -------------------------------------------------------------------------------- /mp7_tracking_down_a_bug/die.py: -------------------------------------------------------------------------------- 1 | from random import randint 2 | 3 | class Die: 4 | """A class representing a single die.""" 5 | 6 | def __init__(self, num_sides=6): 7 | """Assume a six-sided die.""" 8 | self.num_sides = num_sides 9 | 10 | def roll(self): 11 | """"Return a random value between 1 and number of sides.""" 12 | return randint(1, self.num_sides) -------------------------------------------------------------------------------- /mp44_oop6_str_repr/bonsai_2.py: -------------------------------------------------------------------------------- 1 | class BonsaiTree: 2 | 3 | def __init__(self, name, description=""): 4 | self.name = name 5 | self.description = description 6 | 7 | def describe_tree(self): 8 | msg = f"{self.name}: {self.description}" 9 | print(msg) 10 | 11 | def __str__(self): 12 | return self.name 13 | 14 | tree = BonsaiTree("Winged Elm") 15 | print(tree) 16 | -------------------------------------------------------------------------------- /mp20_list_gotchas/card_game_two_players.py: -------------------------------------------------------------------------------- 1 | from player import Player 2 | from dealer import get_card 3 | 4 | eric = Player('Eric') 5 | kyle = Player('Kyle') 6 | 7 | eric.show_cards() 8 | kyle.show_cards() 9 | 10 | for _ in range(5): 11 | new_card = get_card() 12 | eric.hand.append(new_card) 13 | 14 | new_card = get_card() 15 | kyle.hand.append(new_card) 16 | 17 | eric.show_cards() 18 | kyle.show_cards() -------------------------------------------------------------------------------- /mp61_oop16/triangle_nums.py: -------------------------------------------------------------------------------- 1 | import matplotlib.pyplot as plt 2 | 3 | # Generate data. 4 | triangle_nums = [1, 3, 6, 10, 15, 21] 5 | x_values = [1, 2, 3, 4, 5, 6] 6 | 7 | # Generate plot. 8 | fig, ax = plt.subplots() 9 | ax.scatter(x_values, triangle_nums) 10 | 11 | # Format plot. 12 | ax.set_title("Triangle Numbers") 13 | ax.set_xlabel("N") 14 | ax.set_ylabel("Nth Triangle Number") 15 | 16 | # Show plot. 17 | plt.show() -------------------------------------------------------------------------------- /mp149_debugging_8/card_data.py: -------------------------------------------------------------------------------- 1 | suits_symbols = { 2 | "spades": "\u2660", 3 | "hearts": "\u2665", 4 | "diamonds": "\u2666", 5 | "clubs": "\u2663", 6 | } 7 | 8 | ranks_values = { 9 | "2": 2, 10 | "3": 3, 11 | "4": 4, 12 | "5": 5, 13 | "6": 6, 14 | "7": 7, 15 | "8": 8, 16 | "9": 9, 17 | "10": 10, 18 | "J": 11, 19 | "Q": 12, 20 | "K": 13, 21 | "A": 14, 22 | } 23 | -------------------------------------------------------------------------------- /mp150_debugging_9/card_data.py: -------------------------------------------------------------------------------- 1 | suits_symbols = { 2 | "spades": "\u2660", 3 | "hearts": "\u2665", 4 | "diamonds": "\u2666", 5 | "clubs": "\u2663", 6 | } 7 | 8 | ranks_values = { 9 | "2": 2, 10 | "3": 3, 11 | "4": 4, 12 | "5": 5, 13 | "6": 6, 14 | "7": 7, 15 | "8": 8, 16 | "9": 9, 17 | "10": 10, 18 | "J": 11, 19 | "Q": 12, 20 | "K": 13, 21 | "A": 14, 22 | } 23 | -------------------------------------------------------------------------------- /mp20_list_gotchas/fixed/card_game_two_players.py: -------------------------------------------------------------------------------- 1 | from player import Player 2 | from dealer import get_card 3 | 4 | eric = Player('Eric') 5 | kyle = Player('Kyle') 6 | 7 | eric.show_cards() 8 | kyle.show_cards() 9 | 10 | for _ in range(5): 11 | new_card = get_card() 12 | eric.hand.append(new_card) 13 | 14 | new_card = get_card() 15 | kyle.hand.append(new_card) 16 | 17 | eric.show_cards() 18 | kyle.show_cards() -------------------------------------------------------------------------------- /mp8_lists_closer_look_lists_tuples/poker_hands.py: -------------------------------------------------------------------------------- 1 | from random import choice 2 | 3 | all_cards = [2, 3, 4, 5, 6, 7, 8, 9, 10, 'j', 'q', 'k', 'a'] 4 | 5 | def get_hand(hand_size=5): 6 | """Return a hand of cards.""" 7 | return [choice(all_cards) for _ in range(hand_size)] 8 | 9 | num_hands = 10 10 | hands = [get_hand() for _ in range(num_hands)] 11 | 12 | print(f"\nGenerated {len(hands):,} hands.") 13 | print(hands[0]) -------------------------------------------------------------------------------- /mp10_lists_profiling/sum_squares_optimize_get_squares.py: -------------------------------------------------------------------------------- 1 | def get_squares(): 2 | """Return a list of square numbers.""" 3 | return [x**2 for x in range(50_000_000)] 4 | 5 | def get_sum(squares): 6 | """Return the sum of all squares.""" 7 | sum = 0 8 | for square in squares: 9 | sum += square 10 | 11 | return sum 12 | 13 | squares = get_squares() 14 | sum = get_sum(squares) 15 | print(f"Sum: {sum:,}") -------------------------------------------------------------------------------- /mp154_debugging_11/card_data.py: -------------------------------------------------------------------------------- 1 | suits_symbols = { 2 | "spades": "\u2660", 3 | "hearts": "\u2665", 4 | "diamonds": "\u2666", 5 | "clubs": "\u2663", 6 | } 7 | 8 | ranks_values = { 9 | "2": 2, 10 | "3": 3, 11 | "4": 4, 12 | "5": 5, 13 | "6": 6, 14 | "7": 7, 15 | "8": 8, 16 | "9": 9, 17 | "10": 10, 18 | "J": 11, 19 | "Q": 12, 20 | "K": 13, 21 | "A": 14, 22 | } 23 | -------------------------------------------------------------------------------- /mp156_debugging_13/card_data.py: -------------------------------------------------------------------------------- 1 | suits_symbols = { 2 | "spades": "\u2660", 3 | "hearts": "\u2665", 4 | "diamonds": "\u2666", 5 | "clubs": "\u2663", 6 | } 7 | 8 | ranks_values = { 9 | "2": 2, 10 | "3": 3, 11 | "4": 4, 12 | "5": 5, 13 | "6": 6, 14 | "7": 7, 15 | "8": 8, 16 | "9": 9, 17 | "10": 10, 18 | "J": 11, 19 | "Q": 12, 20 | "K": 13, 21 | "A": 14, 22 | } 23 | -------------------------------------------------------------------------------- /mp26_grounding_part_4/main.py: -------------------------------------------------------------------------------- 1 | from cli_args import parse_cli_args 2 | from image_processing import add_border_to_image 3 | 4 | def main(): 5 | # Get the filename and optional CLI args. 6 | args = parse_cli_args() 7 | 8 | # Add border to image and save the new image. 9 | new_img_path = add_border_to_image(args) 10 | print(f"New image saved at {new_img_path}") 11 | 12 | if __name__ == "__main__": 13 | main() -------------------------------------------------------------------------------- /mp29_settings/partial_programs/game_0.py: -------------------------------------------------------------------------------- 1 | class Game: 2 | 3 | def __init__(self): 4 | self.alien_speed = 5 5 | self.alien_direction = 1 6 | 7 | def show_settings(self): 8 | print("\nIn Game:") 9 | print(f" alien speed: {self.alien_speed}") 10 | print(f" alien direction: {self.alien_direction}") 11 | 12 | if __name__ == '__main__': 13 | game = Game() 14 | game.show_settings() -------------------------------------------------------------------------------- /mp3_lists_closer_look/random_numbers_insert.py: -------------------------------------------------------------------------------- 1 | # random_numbers_insert.py 2 | 3 | from random import randint 4 | 5 | # Build a list of random numbers, to simulate rolling a die. 6 | # The most recent roll is always first in the list. 7 | rolls = [] 8 | for _ in range(220_000): 9 | roll = randint(1,6) 10 | rolls.insert(0, roll) 11 | 12 | # Verify how many rolls were generated. 13 | print(f"Generated {len(rolls):,} rolls.") -------------------------------------------------------------------------------- /mp43_substack_notes_cguo/main.py: -------------------------------------------------------------------------------- 1 | import requests 2 | 3 | session = requests.Session() 4 | 5 | # Log in, using the existing session. 6 | login_url = "https://substack.com/api/v1/login" 7 | login_data = { 8 | "redirect": "", 9 | "for_pub": "PUBLICATION", 10 | "email": "MY_EMAIL", 11 | "password": "MY_PASSWORD", 12 | "captcha_response": None, 13 | } 14 | 15 | login_response = session.post(login_url, json=login_data) -------------------------------------------------------------------------------- /mp151_debugging_10/go_fish_fixed/card_data.py: -------------------------------------------------------------------------------- 1 | suits_symbols = { 2 | "spades": "\u2660", 3 | "hearts": "\u2665", 4 | "diamonds": "\u2666", 5 | "clubs": "\u2663", 6 | } 7 | 8 | ranks_values = { 9 | "2": 2, 10 | "3": 3, 11 | "4": 4, 12 | "5": 5, 13 | "6": 6, 14 | "7": 7, 15 | "8": 8, 16 | "9": 9, 17 | "10": 10, 18 | "J": 11, 19 | "Q": 12, 20 | "K": 13, 21 | "A": 14, 22 | } 23 | -------------------------------------------------------------------------------- /mp128_checking_attributes/wx_reporter_3_hasattr.py: -------------------------------------------------------------------------------- 1 | import wx_observer 2 | import wx_observer_wind 3 | 4 | def show_summary(obs): 5 | print("\nObservation summary:") 6 | print(f" Precipitation: {obs.precip}cm") 7 | print(f" Temp: {obs.temp}C") 8 | 9 | if hasattr(obs, "wind"): 10 | print(f" Wind: {obs.wind}kph") 11 | 12 | show_summary(wx_observer.wx_obs) 13 | show_summary(wx_observer_wind.wx_obs) 14 | -------------------------------------------------------------------------------- /mp151_debugging_10/cards_with_error/card_data.py: -------------------------------------------------------------------------------- 1 | suits_symbols = { 2 | "spades": "\u2660", 3 | "hearts": "\u2665", 4 | "diamonds": "\u2666", 5 | "clubs": "\u2663", 6 | } 7 | 8 | ranks_values = { 9 | "2": 2, 10 | "3": 3, 11 | "4": 4, 12 | "5": 5, 13 | "6": 6, 14 | "7": 7, 15 | "8": 8, 16 | "9": 9, 17 | "10": 10, 18 | "J": 11, 19 | "Q": 12, 20 | "K": 13, 21 | "A": 14, 22 | } 23 | -------------------------------------------------------------------------------- /mp151_debugging_10/go_fish_with_error/card_data.py: -------------------------------------------------------------------------------- 1 | suits_symbols = { 2 | "spades": "\u2660", 3 | "hearts": "\u2665", 4 | "diamonds": "\u2666", 5 | "clubs": "\u2663", 6 | } 7 | 8 | ranks_values = { 9 | "2": 2, 10 | "3": 3, 11 | "4": 4, 12 | "5": 5, 13 | "6": 6, 14 | "7": 7, 15 | "8": 8, 16 | "9": 9, 17 | "10": 10, 18 | "J": 11, 19 | "Q": 12, 20 | "K": 13, 21 | "A": 14, 22 | } 23 | -------------------------------------------------------------------------------- /mp155_debugging_12/go_fish_bugfix/card_data.py: -------------------------------------------------------------------------------- 1 | suits_symbols = { 2 | "spades": "\u2660", 3 | "hearts": "\u2665", 4 | "diamonds": "\u2666", 5 | "clubs": "\u2663", 6 | } 7 | 8 | ranks_values = { 9 | "2": 2, 10 | "3": 3, 11 | "4": 4, 12 | "5": 5, 13 | "6": 6, 14 | "7": 7, 15 | "8": 8, 16 | "9": 9, 17 | "10": 10, 18 | "J": 11, 19 | "Q": 12, 20 | "K": 13, 21 | "A": 14, 22 | } 23 | -------------------------------------------------------------------------------- /mp155_debugging_12/go_fish_seeded/card_data.py: -------------------------------------------------------------------------------- 1 | suits_symbols = { 2 | "spades": "\u2660", 3 | "hearts": "\u2665", 4 | "diamonds": "\u2666", 5 | "clubs": "\u2663", 6 | } 7 | 8 | ranks_values = { 9 | "2": 2, 10 | "3": 3, 11 | "4": 4, 12 | "5": 5, 13 | "6": 6, 14 | "7": 7, 15 | "8": 8, 16 | "9": 9, 17 | "10": 10, 18 | "J": 11, 19 | "Q": 12, 20 | "K": 13, 21 | "A": 14, 22 | } 23 | -------------------------------------------------------------------------------- /mp26_grounding_part_4/partial_programs/main_3.py: -------------------------------------------------------------------------------- 1 | from cli_args import parse_cli_args 2 | from image_processing import add_border_to_image 3 | 4 | def main(): 5 | # Get the filename and optional CLI args. 6 | args = parse_cli_args() 7 | 8 | # Add border to image and save the new image. 9 | new_img_path = add_border_to_image(args) 10 | print(f"New image saved at {new_img_path}") 11 | 12 | if __name__ == "__main__": 13 | main() -------------------------------------------------------------------------------- /mp65_october_wx/october_temps_2_october_data.py: -------------------------------------------------------------------------------- 1 | from pathlib import Path 2 | import pandas as pd 3 | 4 | path = Path('wx_data/sitka_temps_1983_2023.csv') 5 | df_all = pd.read_csv(path) 6 | df_all['DATE'] = pd.to_datetime(df_all['DATE']) 7 | 8 | # Keep only October's data for each year. 9 | df_october = df_all[df_all['DATE'].dt.month == 10] 10 | 11 | dates = df_october['DATE'] 12 | highs = df_october['TMAX'] 13 | 14 | print(dates[:5], highs[:5]) -------------------------------------------------------------------------------- /mp143_debugging_4/die.py: -------------------------------------------------------------------------------- 1 | import random 2 | import os 3 | from dataclasses import dataclass 4 | 5 | 6 | # Set a random seed when testing. 7 | if seed := os.environ.get("DICE_BATTLE_RANDOM_SEED"): 8 | random.seed(int(seed)) 9 | 10 | 11 | @dataclass 12 | class Die: 13 | """Model a single die.""" 14 | 15 | num_sides: int = 6 16 | 17 | def roll(self): 18 | """Roll the die.""" 19 | return random.randint(1, self.num_sides) -------------------------------------------------------------------------------- /mp39_oop3_init/greeter_4_initialize_object.py: -------------------------------------------------------------------------------- 1 | class Greeter: 2 | """Greet people in a variety of ways.""" 3 | 4 | def initialize_object(self, tone="casual"): 5 | self.tone = tone 6 | 7 | def say_hello(self): 8 | if self.tone == "casual": 9 | print("Hi.") 10 | elif self.tone == "formal": 11 | print("Hello.") 12 | 13 | greeter = Greeter() 14 | greeter.initialize_object() 15 | greeter.say_hello() -------------------------------------------------------------------------------- /mp126_function_checklist/fn_checklist_6_simpler_approach.py: -------------------------------------------------------------------------------- 1 | from pathlib import Path 2 | import re 3 | import sys 4 | 5 | # Read program file. 6 | path = Path(sys.argv[1]) 7 | contents = path.read_text() 8 | 9 | # Find all function names. 10 | fn_name_re = r".*def ([a-z_]*)\(" 11 | fn_names = re.findall(fn_name_re, contents) 12 | 13 | # Generate an issues task list. 14 | for name in fn_names: 15 | task = f"- [ ] `{name}()`" 16 | print(task) 17 | -------------------------------------------------------------------------------- /mp33_using_pandas/high_temp_trends.py: -------------------------------------------------------------------------------- 1 | from pathlib import Path 2 | 3 | import pandas as pd 4 | 5 | def get_data(path): 6 | """Extract dates and high temperatures.""" 7 | df = pd.read_csv(path) 8 | df['DATE'] = pd.to_datetime(df['DATE']) 9 | 10 | return df['DATE'], df['TMAX'] 11 | 12 | # Extract data. 13 | path = Path('wx_data/sitka_highs_1944_2023.csv') 14 | dates, highs = get_data(path) 15 | print(f"\nFound {len(highs):,} data points.") -------------------------------------------------------------------------------- /mp39_oop3_init/greeter_2_tone.py: -------------------------------------------------------------------------------- 1 | class Greeter: 2 | """Greet people in a variety of ways.""" 3 | 4 | def __init__(self, tone="casual"): 5 | self.tone = tone 6 | 7 | def say_hello(self): 8 | if self.tone == "casual": 9 | print("Hi.") 10 | elif self.tone == "formal": 11 | print("Hello.") 12 | 13 | greeter = Greeter() 14 | greeter.say_hello() 15 | 16 | greeter.tone = "formal" 17 | greeter.say_hello() -------------------------------------------------------------------------------- /mp3_lists_closer_look/list_memory.py: -------------------------------------------------------------------------------- 1 | # list_memory.py 2 | 3 | import sys 4 | from random import randint 5 | 6 | # Build a list of random numbers, to simulate rolling a die. 7 | rolls = [] 8 | for x in range(10): 9 | roll = randint(1,6) 10 | rolls.append(roll) 11 | 12 | # Examine the length and size of the list. 13 | list_length = len(rolls) 14 | list_size = sys.getsizeof(rolls) 15 | print(f"Items: {list_length}\tBytes: {list_size}") -------------------------------------------------------------------------------- /mp39_oop3_init/greeter_3_misspelled.py: -------------------------------------------------------------------------------- 1 | class Greeter: 2 | """Greet people in a variety of ways.""" 3 | 4 | def _init__(self, tone="casual"): 5 | self.tone = tone 6 | 7 | def say_hello(self): 8 | if self.tone == "casual": 9 | print("Hi.") 10 | elif self.tone == "formal": 11 | print("Hello.") 12 | 13 | greeter = Greeter() 14 | greeter.say_hello() 15 | 16 | greeter.tone = "formal" 17 | greeter.say_hello() -------------------------------------------------------------------------------- /mp47_oop8_comparison_methods/river_3_lt_eq.py: -------------------------------------------------------------------------------- 1 | class River: 2 | 3 | def __init__(self, name, length=0): 4 | self.name = name 5 | # Length in km. 6 | self.length = length 7 | 8 | def __gt__(self, river_2): 9 | return self.length > river_2.length 10 | 11 | def __lt__(self, river_2): 12 | return self.length < river_2.length 13 | 14 | def __eq__(self, river_2): 15 | return self.length == river_2.length -------------------------------------------------------------------------------- /mp37_oop2_self/robot_expanded.py: -------------------------------------------------------------------------------- 1 | class Robot: 2 | """A class representing simple robots.""" 3 | 4 | def __init__(self, name=""): 5 | self.name = name 6 | self.type = "drone" 7 | self.mass_grams = 249 8 | 9 | def say_hello(self): 10 | print(f"Hi, I'm {self.name}!") 11 | print(f"I'm a {self.type}.") 12 | print(f"I have a mass of {self.mass_grams}g.") 13 | 14 | my_robot = Robot("William") 15 | my_robot.say_hello() -------------------------------------------------------------------------------- /mp3_lists_closer_look/random_numbers_deque.py: -------------------------------------------------------------------------------- 1 | # random_numbers_deque.py 2 | 3 | from random import randint 4 | from collections import deque 5 | 6 | # Build a list of random numbers, to simulate rolling a die. 7 | # The most recent roll is always first in the list. 8 | rolls = deque() 9 | for _ in range(20_000_000): 10 | roll = randint(1,6) 11 | rolls.appendleft(roll) 12 | 13 | # Verify how many rolls were generated. 14 | print(f"Generated {len(rolls):,} rolls.") -------------------------------------------------------------------------------- /mp58_urlspy_order/pianos/views.py: -------------------------------------------------------------------------------- 1 | from django.http import HttpResponse 2 | 3 | def index(request): 4 | msg = "Welcome to the Piano Store!" 5 | return HttpResponse(msg) 6 | 7 | def about(request): 8 | msg = "About the Piano Store" 9 | return HttpResponse(msg) 10 | 11 | def contact(request): 12 | msg = "Contact the Piano Store" 13 | return HttpResponse(msg) 14 | 15 | def faq(request): 16 | msg = "Piano Store FAQ" 17 | return HttpResponse(msg) -------------------------------------------------------------------------------- /mp128_checking_attributes/wx_reporter_2_try_except.py: -------------------------------------------------------------------------------- 1 | import wx_observer 2 | import wx_observer_wind 3 | 4 | def show_summary(obs): 5 | print("\nObservation summary:") 6 | print(f" Precipitation: {obs.precip}cm") 7 | print(f" Temp: {obs.temp}C") 8 | 9 | try: 10 | print(f" Wind: {obs.wind}kph") 11 | except AttributeError: 12 | pass 13 | 14 | show_summary(wx_observer.wx_obs) 15 | show_summary(wx_observer_wind.wx_obs) 16 | -------------------------------------------------------------------------------- /mp130_door_codes/key_code_4_refactored.py: -------------------------------------------------------------------------------- 1 | from random import choices 2 | import sys 3 | 4 | try: 5 | length = int(sys.argv[1]) 6 | except IndexError: 7 | length = 6 8 | 9 | def get_keycode(): 10 | """Generate a reasonably secure keycode.""" 11 | while True: 12 | keycode = choices("0123456789", k=length) 13 | if len(set(keycode)) == length - 1: 14 | return "".join(keycode) 15 | 16 | keycode = get_keycode() 17 | print(keycode) 18 | -------------------------------------------------------------------------------- /mp13_lists_sets/explore_responses_set.py: -------------------------------------------------------------------------------- 1 | from pathlib import Path 2 | import json 3 | 4 | path = Path('responses.json') 5 | contents = path.read_text() 6 | responses = json.loads(contents) 7 | 8 | num_responses = len(responses) 9 | print(f"Found {num_responses:,} responses.") 10 | 11 | # Find the unique responses. 12 | unique_responses = set(responses) 13 | 14 | num_unique = len(unique_responses) 15 | print(f"Found {num_unique} unique responses.") 16 | print(unique_responses) -------------------------------------------------------------------------------- /mp55_oop13_serialization_abc/robot_class.py: -------------------------------------------------------------------------------- 1 | from pathlib import Path 2 | import json 3 | 4 | class Robot: 5 | 6 | def __init__(self, name=""): 7 | self.name = name 8 | 9 | def say_hi(self): 10 | print(f"Hi, I'm {self.name} the robot.") 11 | 12 | # Create an instance of Robot. 13 | robot = Robot('Marvin') 14 | 15 | # Convert the data to JSON, and save it. 16 | robot_data = json.dumps(robot) 17 | path = Path("robot.json") 18 | path.write_text(robot_data) -------------------------------------------------------------------------------- /mp61_oop16/triangle_nums_2_print_fig_ax.py: -------------------------------------------------------------------------------- 1 | import matplotlib.pyplot as plt 2 | 3 | # Generate data. 4 | triangle_nums = [1, 3, 6, 10, 15, 21] 5 | x_values = [1, 2, 3, 4, 5, 6] 6 | 7 | # Generate plot. 8 | fig, ax = plt.subplots() 9 | ax.scatter(x_values, triangle_nums) 10 | print(type(fig)) 11 | print(type(ax)) 12 | 13 | # Format plot. 14 | ax.set_title("Triangle Numbers") 15 | ax.set_xlabel("N") 16 | ax.set_ylabel("Nth Triangle Number") 17 | 18 | # Show plot. 19 | plt.show() -------------------------------------------------------------------------------- /mp26_grounding_part_4/partial_programs/cli_args_1.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | def parse_cli_args(argv): 4 | try: 5 | path = Path(argv[1]) 6 | except IndexError: 7 | print("You must provide a target image.") 8 | sys.exit() 9 | 10 | border_width = int(argv[2]) if len(argv) > 2 else 2 11 | padding = int(argv[3]) if len(argv) > 3 else 0 12 | border_color = argv[4] if len(argv) > 4 else "lightgray" 13 | 14 | return path, border_width, padding, border_color -------------------------------------------------------------------------------- /mp61_oop16/triangle_nums_3_facecolor.py: -------------------------------------------------------------------------------- 1 | import matplotlib.pyplot as plt 2 | 3 | # Generate data. 4 | triangle_nums = [1, 3, 6, 10, 15, 21] 5 | x_values = [1, 2, 3, 4, 5, 6] 6 | 7 | # Generate plot. 8 | fig, ax = plt.subplots(facecolor='#9ccbf0') 9 | ax.scatter(x_values, triangle_nums) 10 | print(type(fig)) 11 | print(type(ax)) 12 | 13 | # Format plot. 14 | ax.set_title("Triangle Numbers") 15 | ax.set_xlabel("N") 16 | ax.set_ylabel("Nth Triangle Number") 17 | 18 | # Show plot. 19 | plt.show() -------------------------------------------------------------------------------- /mp24_grounding_part_3/partial_programs/add_border_9.py: -------------------------------------------------------------------------------- 1 | """Add a border to any image.""" 2 | 3 | from cli import process_cli_args 4 | import image_functions as img_fns 5 | 6 | 7 | # Set default options. 8 | options = { 9 | 'border_width': 2, 10 | 'padding': 0, 11 | 'border_color': 'lightgray' 12 | } 13 | 14 | # Process image. 15 | path = process_cli_args(options) 16 | img = img_fns.load_image(path) 17 | new_img = img_fns.process_image(img, options) 18 | img_fns.save_image(path, new_img) -------------------------------------------------------------------------------- /mp58_urlspy_order/piano_store/asgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | ASGI config for piano_store project. 3 | 4 | It exposes the ASGI callable as a module-level variable named ``application``. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/4.2/howto/deployment/asgi/ 8 | """ 9 | 10 | import os 11 | 12 | from django.core.asgi import get_asgi_application 13 | 14 | os.environ.setdefault("DJANGO_SETTINGS_MODULE", "piano_store.settings") 15 | 16 | application = get_asgi_application() 17 | -------------------------------------------------------------------------------- /mp58_urlspy_order/piano_store/wsgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | WSGI config for piano_store project. 3 | 4 | It exposes the WSGI callable as a module-level variable named ``application``. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/4.2/howto/deployment/wsgi/ 8 | """ 9 | 10 | import os 11 | 12 | from django.core.wsgi import get_wsgi_application 13 | 14 | os.environ.setdefault("DJANGO_SETTINGS_MODULE", "piano_store.settings") 15 | 16 | application = get_wsgi_application() 17 | -------------------------------------------------------------------------------- /mp126_function_checklist/fn_checklist_2_all_fn_names.py: -------------------------------------------------------------------------------- 1 | from pathlib import Path 2 | import re 3 | 4 | path = Path(__file__).parent / "deploy.py" 5 | 6 | # Get all lines with a function definition. 7 | lines = [ 8 | line 9 | for line in path.read_text().splitlines() 10 | if ' def ' in line 11 | ] 12 | 13 | # Extract each function name. 14 | fn_name_re = r".*def ([a-z_]*)\(" 15 | fn_names = [ 16 | re.match(fn_name_re, line).group(1) 17 | for line in lines 18 | ] 19 | 20 | breakpoint() -------------------------------------------------------------------------------- /mp37_oop2_self/robot_self_dict.py: -------------------------------------------------------------------------------- 1 | class Robot: 2 | """A class representing simple robots.""" 3 | 4 | def __init__(self, name=""): 5 | self.name = name 6 | self.type = "drone" 7 | self.mass_grams = 249 8 | print(self.__dict__) 9 | 10 | def say_hello(self): 11 | print(f"Hi, I'm {self.name}!") 12 | print(f"I'm a {self.type}.") 13 | print(f"I have a mass of {self.mass_grams}g.") 14 | 15 | my_robot = Robot("William") 16 | my_robot.say_hello() -------------------------------------------------------------------------------- /mp10_lists_profiling/sum_squares.py: -------------------------------------------------------------------------------- 1 | def get_squares(): 2 | """Return a list of square numbers.""" 3 | squares = [] 4 | for x in range(50_000_000): 5 | square = x**2 6 | squares.append(square) 7 | 8 | return squares 9 | 10 | def get_sum(squares): 11 | """Return the sum of all squares.""" 12 | sum = 0 13 | for square in squares: 14 | sum += square 15 | 16 | return sum 17 | 18 | squares = get_squares() 19 | sum = get_sum(squares) 20 | print(f"Sum: {sum:,}") -------------------------------------------------------------------------------- /mp17_lists_modifying_in_loop/process_requests_good.py: -------------------------------------------------------------------------------- 1 | # process_requests_gotcha.py 2 | 3 | # Make a mix of valid and invalid requests. 4 | requests = [ 5 | 'request_0', 'request_1_bad', 'request_2', 6 | 'request_3_bad', 'request_4_bad', 'request_5', 7 | 'request_6', 'request_7_bad', 'request_8', 8 | 'request_9_bad', 'request_10', 'request_11_bad' 9 | ] 10 | 11 | # Keep only valid requests. 12 | requests = [r for r in requests if 'bad' not in r] 13 | 14 | # Show what's left. 15 | print(requests) -------------------------------------------------------------------------------- /mp3_lists_closer_look/random_numbers.py: -------------------------------------------------------------------------------- 1 | # random_numbers.py 2 | 3 | from random import randint 4 | 5 | # Build a list of random numbers, to simulate rolling a die. 6 | rolls = [] 7 | for _ in range(20_000_000): 8 | roll = randint(1,6) 9 | rolls.append(roll) 10 | 11 | # Verify how many rolls were generated. 12 | print(f"Generated {len(rolls):,} rolls.") 13 | 14 | # Print the first ten rolls, and the last ten rolls. 15 | print(f"First ten rolls: {rolls[:10]}") 16 | print(f"Last ten rolls: {rolls[-10:]}") -------------------------------------------------------------------------------- /mp78_streamlit_basics/roller_num_dice_slider.py: -------------------------------------------------------------------------------- 1 | from random import randint 2 | import streamlit as st 3 | 4 | # Input widgets 5 | side_options = [6, 10, 12, 20] 6 | num_sides = st.radio("Number of sides:", side_options) 7 | num_dice = st.slider("Number of dice:", 1, 10, value=2) 8 | 9 | st.button("Roll") 10 | 11 | # Roll calculation 12 | rolls = [randint(1, num_sides) for _ in range(num_dice)] 13 | roll = sum(rolls) 14 | 15 | # Output message 16 | st.write("---") 17 | st.subheader(roll) 18 | st.write(str(rolls)) -------------------------------------------------------------------------------- /oop_18/partial_versions/climbing_library_0.py: -------------------------------------------------------------------------------- 1 | from library_models import Library, Book, Patron 2 | 3 | # Create a library. 4 | library = Library(name="The Climber's Library") 5 | 6 | # Create some books. 7 | book = Book( 8 | title="Freedom of the Hills", 9 | author="The Mountaineers", 10 | ) 11 | library.resources.append(book) 12 | 13 | book = Book( 14 | title="Learning to Fly", 15 | author="Steph Davis", 16 | ) 17 | library.resources.append(book) 18 | 19 | # Show all books. 20 | library.show_books() -------------------------------------------------------------------------------- /mp2_lists_closer_look/bookshelf.c: -------------------------------------------------------------------------------- 1 | #include" in line:
30 | process_code_block(line, lines_iter, modified_lines)
31 | else:
32 | # Keep the line as is.
33 | modified_lines.append(line)
34 |
35 | # Write the modified lines into the template.
36 | post_html = "\n".join(modified_lines)
37 |
38 | eml_string = template.replace('post_body', post_html)
39 |
40 | output_file = Path('output_files/modified_test_email.eml')
41 | output_file.write_text(eml_string)
--------------------------------------------------------------------------------
/mp124_real_estate_images/image_archiver_3_first_full_image.py:
--------------------------------------------------------------------------------
1 | from pathlib import Path
2 |
3 | import httpx
4 |
5 | from selenium import webdriver
6 | from selenium.webdriver.chrome.service import Service
7 | from webdriver_manager.chrome import ChromeDriverManager
8 | from selenium.webdriver.common.by import By
9 | from selenium.webdriver.support.ui import WebDriverWait
10 | from selenium.webdriver.support import expected_conditions as EC
11 |
12 |
13 | url = "https://www.zillow.com/homedetails/"
14 | url += "432-Park-Ave-PENTHOUSE-New-York-NY-10022/2069500049_zpid/"
15 |
16 | driver = webdriver.Chrome(
17 | service=Service(ChromeDriverManager().install()))
18 |
19 | # Open main property page.
20 | driver.get(url)
21 |
22 | # Click on first image in listing.
23 | button = WebDriverWait(driver, 10).until(
24 | EC.element_to_be_clickable((
25 | By.CSS_SELECTOR,
26 | "button[aria-label='view larger view of the 1 photo of this home']"
27 | ))
28 | )
29 | button.click()
30 |
31 | # On main photos page. Click first image button.
32 | li_element = WebDriverWait(driver, 10).until(
33 | EC.presence_of_element_located((
34 | By.CSS_SELECTOR, "li.viw-tile-0"))
35 | )
36 | button = li_element.find_element(
37 | By.CSS_SELECTOR, "button[data-cy='loaded-photo-tile']")
38 | button.click()
39 |
40 | breakpoint()
41 |
--------------------------------------------------------------------------------
/mp123_mortgages/mortgage_analysis_1.py:
--------------------------------------------------------------------------------
1 | """Analyze a mortgage loan."""
2 |
3 | purchase_price = 500_000
4 | interest_rate = 0.075
5 | loan_term = 360
6 |
7 | # Find a monthly payment that pays off the loan.
8 | monthly_payment = 1.00
9 | principal = purchase_price
10 |
11 | total_principal = 0
12 | total_interest = 0
13 | while True:
14 | # Run the life of the loan with the current payment.
15 | for payment_num in range(loan_term):
16 | interest = (interest_rate/12) * principal
17 | toward_principal = monthly_payment - interest
18 | principal -= toward_principal
19 |
20 | total_interest += interest
21 | total_principal += toward_principal
22 |
23 | # Exit loop if loan is paid off.
24 | if principal <= 0:
25 | break
26 |
27 | # Loan was not paid off. Increase monthly payment, and reset loan.
28 | monthly_payment += 1.00
29 | principal = purchase_price
30 |
31 | total_principal = 0
32 | total_interest = 0
33 |
34 | # Summarize loan.
35 | total_paid = total_principal + total_interest
36 | print("Loan summary:")
37 | print(f" Purchase price: ${purchase_price:,.2f}")
38 | print(f" Monthly payment: ${monthly_payment:,.2f}")
39 | print(f" Principal paid: ${total_principal:,.2f}")
40 | print(f" Total interest paid: ${total_interest:,.2f}")
41 | print(f" Total paid: ${total_paid:,.2f}")
42 |
--------------------------------------------------------------------------------
/mp154_debugging_11/go_fish_utils.py:
--------------------------------------------------------------------------------
1 | """Utility functions for the Go Fish game."""
2 |
3 | import subprocess
4 | import sys
5 |
6 | def get_player_guess(player_hand):
7 | """Get a valid guess from the player."""
8 | msg = "\nWhat card would you like to ask for? "
9 | requested_card = input(msg).upper()
10 |
11 | if requested_card == "QUIT":
12 | sys.exit("\nThanks for playing!")
13 | if requested_card not in "2345678910JQKA":
14 | print("Invalid entry, please try again.")
15 | get_player_guess(player_hand)
16 |
17 | player_ranks = [c.rank for c in player_hand.cards]
18 | if requested_card not in player_ranks:
19 | print("You don't have that card!")
20 | get_player_guess(player_hand)
21 |
22 | # Valid response.
23 | return requested_card
24 |
25 | def remove_card(target_rank, hand):
26 | """Remove the first card with a matching rank, and return it."""
27 | for card in hand.cards:
28 | if card.rank == target_rank:
29 | hand.cards.remove(card)
30 | return card
31 |
32 | def clear_terminal():
33 | """Clear the terminal."""
34 | # Don't clear terminal in verbose mode.
35 | if "-v" in sys.argv:
36 | return
37 |
38 | if sys.platform == "win32":
39 | subprocess.run("cls")
40 | else:
41 | subprocess.run("clear")
--------------------------------------------------------------------------------