René's URL Explorer Experiment


Title: Make the Maze Self-Contained (Video) – Real Python

Open Graph Title: Make the Maze Self-Contained – Real Python

Description: Making Maze Self-Contained. To make your Maze class more self-contained, you may augment it with .load() and .dump() methods that will delegate processing to their respective counterparts in the serializer module. However, doing so without any…

Open Graph Description: Making Maze Self-Contained. To make your Maze class more self-contained, you may augment it with .load() and .dump() methods that will delegate processing to their respective counterparts in the serializer module. However, doing so without any…

Opengraph URL: https://realpython.com/lessons/python-self-contained-maze/

X: @realpython

direct link

Domain: realpython.com


Hey, it has json ld scripts:
  {
    "@context": "https://schema.org",
    "@type": "VideoObject",
    "name": "Make the Maze Self\u002DContained",
    "description": "Making Maze Self\u002DContained. To make your Maze class more self\u002Dcontained, you may augment it with .load() and .dump() methods that will delegate processing to their respective counterparts in the serializer module. However, doing so without any…",
    "thumbnailUrl": ["https://files.realpython.com/media/Build-a-Pac-Man-Maze-Solver-in-Python_Watermarked.c2e79a85fc99.jpg"],
    "uploadDate": "2023-06-06T14:00:00+00:00",
    "duration": "PT4M30S",
    
    "potentialAction": {
      "@type": "SeekToAction",
      "target": "https://realpython.com/lessons/python-self-contained-maze/#t={seek_to_second_number}",
      "startOffset-input": "required name=seek_to_second_number"
    }
  }
  

authorReal Python
theme-color#18354c
color-schemelight dark
twitter:cardsummary_large_image
twitter:imagehttps://files.realpython.com/media/Build-a-Pac-Man-Maze-Solver-in-Python_Watermarked.c2e79a85fc99.jpg
og:imagehttps://files.realpython.com/media/Build-a-Pac-Man-Maze-Solver-in-Python_Watermarked.c2e79a85fc99.jpg
twitter:creator@realpython
og:typevideo.episode
og:site_nameReal Python
apple-mobile-web-app-titleReal Python

Links:

https://realpython.com/
Start Herehttps://realpython.com/start-here/
Learn Python https://realpython.com/lessons/python-self-contained-maze/
Your Learning Plan →Your personalized Python learning planhttps://realpython.com/account/learning-plan/
Python Tutorials →In-depth articles and video courseshttps://realpython.com/search?kind=article&kind=course&order=newest&_from=nav_library
Learning Paths →Guided study plans for accelerated learninghttps://realpython.com/learning-paths/
Quizzes & Exercises →Check your learning progresshttps://realpython.com/search?kind=exercise&kind=quiz&_from=nav_library
Browse Topics →Focus on a specific area or skill levelhttps://realpython.com/tutorials/all/
Reference →Concise definitions for common Python termshttps://realpython.com/ref/
Mentor AI →NewYour personal Python mentorhttps://realpython.com/mentor/
Office Hours →Live Q&A calls with Python expertshttps://realpython.com/office-hours/
Community Chat →Learn with other Pythonistashttps://realpython.com/community/
Live Courses →Live, instructor-led Python courseshttps://realpython.com/live/
Books →Round out your knowledge and learn offlinehttps://realpython.com/products/books/
Podcast →Hear what’s new in the world of Pythonhttps://realpython.com/podcasts/rpp/
Unlock All Content and Become a Python Expert →Get unlimited access to all Real Python has to offerhttps://realpython.com/account/join/?from=navbar_learn
Unlock All Content →Become a Python Experthttps://realpython.com/account/join/?from=navbar_learn
More https://realpython.com/lessons/python-self-contained-maze/
Learner Storieshttps://realpython.com/learner-stories/
Python Newsletterhttps://realpython.com/newsletter/
Python Job Boardhttps://www.pythonjobshq.com
Meet the Teamhttps://realpython.com/team/
Become a Contributorhttps://realpython.com/jobs/
Searchhttps://realpython.com/search
https://realpython.com/search
Joinhttps://realpython.com/account/join/
Sign‑Inhttps://realpython.com/account/login/?intent=navbar&next=%2Flessons%2Fpython-self-contained-maze%2F
Unlock This Lessonhttps://realpython.com/account/join/?utm_source=rp_lesson&utm_content=python-maze-solver
Unlock This Lessonhttps://realpython.com/account/join/?utm_source=rp_lesson&utm_content=python-maze-solver
https://realpython.com/courses/python-maze-solver/#team
Mazes in Python: Build, Visualize, Store, and Solvehttps://realpython.com/courses/python-maze-solver/
Darren Joneshttps://realpython.com/courses/python-maze-solver/#team
Recommended Tutorialhttps://realpython.com/python-maze-solver/
Course Slides (.pdf)https://realpython.com/courses/python-maze-solver/downloads/mazes-in-python-slides/
Sample Code (.zip)https://realpython.com/courses/python-maze-solver/downloads/mazes-in-python-code/
Ask a Questionhttps://realpython.com/lessons/python-self-contained-maze/#discussion
https://realpython.com/feedback/survey/course/python-maze-solver/liked/?from=lesson-title
https://realpython.com/feedback/survey/course/python-maze-solver/disliked/?from=lesson-title
Contentshttps://realpython.com/lessons/python-self-contained-maze/#description
Transcripthttps://realpython.com/lessons/python-self-contained-maze/#transcript
Discussionhttps://realpython.com/lessons/python-self-contained-maze/#discussion
00:00https://realpython.com/lessons/python-self-contained-maze/#t=0.58
Making Maze Self-Contained.https://realpython.com/lessons/python-self-contained-maze/#t=0.58
To make your Maze class morehttps://realpython.com/lessons/python-self-contained-maze/#t=2.976
self-contained,https://realpython.com/lessons/python-self-contained-maze/#t=5.43
you may augment it with .load() and .dump() methods that will delegate processing tohttps://realpython.com/lessons/python-self-contained-maze/#t=6.57
their respective counterparts in the serializer module.https://realpython.com/lessons/python-self-contained-maze/#t=11.11
00:14https://realpython.com/lessons/python-self-contained-maze/#t=14.613
However,https://realpython.com/lessons/python-self-contained-maze/#t=14.613
doing so without any modifications would inevitably lead to the dreaded circularhttps://realpython.com/lessons/python-self-contained-maze/#t=15.28
dependency, which Python doesn’t allow.https://realpython.com/lessons/python-self-contained-maze/#t=19.72
You can’t have your class depend on functions in another module and the otherhttps://realpython.com/lessons/python-self-contained-maze/#t=22.53
way round at the same time.https://realpython.com/lessons/python-self-contained-maze/#t=26.11
00:29https://realpython.com/lessons/python-self-contained-maze/#t=29.68
There are a few ways to work around this problem,https://realpython.com/lessons/python-self-contained-maze/#t=29.68
and each has its pros and cons.https://realpython.com/lessons/python-self-contained-maze/#t=32.13
The most elegant solution is to break the two-way dependency in one direction.https://realpython.com/lessons/python-self-contained-maze/#t=34.61
00:39https://realpython.com/lessons/python-self-contained-maze/#t=39.91
Since you want to call the serializing code from within your class,https://realpython.com/lessons/python-self-contained-maze/#t=39.91
removing all Maze class references from the serializer module is the onlyhttps://realpython.com/lessons/python-self-contained-maze/#t=43.78
option.https://realpython.com/lessons/python-self-contained-maze/#t=47.74
00:50https://realpython.com/lessons/python-self-contained-maze/#t=50.86
Start refactoring the code by deleting the import statement of Maze from thehttps://realpython.com/lessons/python-self-contained-maze/#t=50.86
serializer module.https://realpython.com/lessons/python-self-contained-maze/#t=55.05
01:04https://realpython.com/lessons/python-self-contained-maze/#t=64.12
As soon as you do that,https://realpython.com/lessons/python-self-contained-maze/#t=64.12
your code editor should flag all unresolved Maze class references in the module.https://realpython.com/lessons/python-self-contained-maze/#t=65.61
You can see the first one in the dump() function at the top of the file.https://realpython.com/lessons/python-self-contained-maze/#t=71.49
01:15https://realpython.com/lessons/python-self-contained-maze/#t=75.98
The function currently accepts a maze object as an argument.https://realpython.com/lessons/python-self-contained-maze/#t=75.98
You can replace this with intermediary data transfer objects, such as Pythonhttps://realpython.com/lessons/python-self-contained-maze/#t=79.26
built-in types or other models.https://realpython.com/lessons/python-self-contained-maze/#t=83.56
01:26https://realpython.com/lessons/python-self-contained-maze/#t=86.69
Rather than serializing a Maze instance,https://realpython.com/lessons/python-self-contained-maze/#t=86.69
you’ll now serialize its building blocks, which the Maze class can put backhttps://realpython.com/lessons/python-self-contained-maze/#t=89.13
together.https://realpython.com/lessons/python-self-contained-maze/#t=93.31
01:39https://realpython.com/lessons/python-self-contained-maze/#t=99.55
Notice that you renamed the function to convey its purpose more accurately byhttps://realpython.com/lessons/python-self-contained-maze/#t=99.55
emphasizing its new interface.https://realpython.com/lessons/python-self-contained-maze/#t=103.89
This change must also cascadehttps://realpython.com/lessons/python-self-contained-maze/#t=109.98
down to the serialize() function, while compress() and decompress() remainhttps://realpython.com/lessons/python-self-contained-maze/#t=111.35
intact.https://realpython.com/lessons/python-self-contained-maze/#t=116.21
02:50https://realpython.com/lessons/python-self-contained-maze/#t=170.22
With this update,https://realpython.com/lessons/python-self-contained-maze/#t=170.22
dump_squares() and serialize() have compatible function signatures once more.https://realpython.com/lessons/python-self-contained-maze/#t=171.54
You’ll modify your deserializing code in a similar way by getting rid of thehttps://realpython.com/lessons/python-self-contained-maze/#t=176.59
dependency on Maze from both load() and deserialize().https://realpython.com/lessons/python-self-contained-maze/#t=180.86
03:25https://realpython.com/lessons/python-self-contained-maze/#t=205.63
The loading function is now named load_squares() to follow a consistent naminghttps://realpython.com/lessons/python-self-contained-maze/#t=205.63
convention, and it returns an iterator of squares rather than a complete maze.https://realpython.com/lessons/python-self-contained-maze/#t=209.98
03:35https://realpython.com/lessons/python-self-contained-maze/#t=215.77
Additionally,https://realpython.com/lessons/python-self-contained-maze/#t=215.77
you simplified the other function, deserialize(), by turning it into a generatorhttps://realpython.com/lessons/python-self-contained-maze/#t=216.27
function, which returns a generator of Square instances.https://realpython.com/lessons/python-self-contained-maze/#t=221.21
04:20https://realpython.com/lessons/python-self-contained-maze/#t=260.04
You’re now free to make edits to the Maze class to reflect the changes you’vehttps://realpython.com/lessons/python-self-contained-maze/#t=260.04
performed in the serializer module,https://realpython.com/lessons/python-self-contained-maze/#t=263.78
and that’s what you’ll be looking at in the next section of the course.https://realpython.com/lessons/python-self-contained-maze/#t=265.52
Become a Memberhttps://realpython.com/account/join/
https://realpython.com/lessons/deserialize-python-maze/
Overviewhttps://realpython.com/courses/python-maze-solver/
https://realpython.com/lessons/python-maze-class/
Mazes in Python: Build and Visualize 02:47 https://realpython.com/videos/python-maze-solver-part-1-overview/
Check Out What You'll Make 02:39 https://realpython.com/videos/python-maze-solver-project/
Lay the Groundwork 04:02 https://realpython.com/videos/python-maze-solver-groundwork/
Scaffold the Project Structure 04:50 https://realpython.com/lessons/python-maze-solver-structure/
Represent the Maze With Objects 06:37 https://realpython.com/lessons/represent-maze-with-objects/
Create Border Patterns 06:32 https://realpython.com/lessons/python-maze-border-patterns/
Model the Square 02:25 https://realpython.com/lessons/model-python-maze-square/
Build the Maze 09:07 https://realpython.com/lessons/build-python-maze/
Visualize the Maze With SVG 04:45 https://realpython.com/lessons/python-maze-svg/
Implement Geometric Primitives 04:48 https://realpython.com/lessons/python-maze-geometric-primitives/
Add More Primitives 03:47 https://realpython.com/lessons/python-maze-more-primitives/
Decompose the Border Into Primitives 04:41 https://realpython.com/lessons/decompose-python-maze-border/
Add More Border Patterns 03:58 https://realpython.com/lessons/python-maze-more-border-patterns/
Build the SVG Renderer 03:49 https://realpython.com/lessons/python-maze-svg-renderer/
Add Features to the Renderer 06:50 https://realpython.com/lessons/python-maze-renderer-features/
Draw the Solution 03:13 https://realpython.com/lessons/draw-python-maze-solution/
Preview the Rendered Maze and Its Solution 04:56 https://realpython.com/lessons/preview-python-maze/
Mazes in Python: Build and Visualize (Recap) 01:14 https://realpython.com/lessons/python-maze-solver-part-1-summary/
Mazes in Python: Store and Solve 01:48 https://realpython.com/videos/python-maze-solver-part-2-overview/
Load the Maze From a Binary File 04:55 https://realpython.com/videos/python-maze-binary-file/
Choose Your Data Alignment 05:09 https://realpython.com/videos/python-maze-data-alignment/
Define the File Header and Body 08:12 https://realpython.com/lessons/python-maze-file-header-and-body/
Serialize the Maze 05:22 https://realpython.com/lessons/serialize-python-maze/
Deserialize the Maze 04:32 https://realpython.com/lessons/deserialize-python-maze/
Make the Maze Self-Contained 04:30 https://realpython.com/lessons/python-self-contained-maze/
Update the Maze Class 03:16 https://realpython.com/lessons/python-maze-class/
Solve the Maze Using a Graph-Based Approach 03:01 https://realpython.com/lessons/solve-python-maze-graph-based/
Transform the Maze Into a Graph 07:06 https://realpython.com/lessons/transform-python-maze-graph/
Find the Shortest Path 05:23 https://realpython.com/lessons/python-maze-shortest-path/
Add Weights to Graph Edges 02:36 https://realpython.com/lessons/python-map-weights-graph-edges/
Introduce Enemies and Rewards 06:04 https://realpython.com/lessons/python-maze-enemies-rewards/
Make a Runnable Script 03:59 https://realpython.com/lessons/python-maze-runnable-script/
Mazes in Python: Store and Solve (Recap) 01:23 https://realpython.com/lessons/python-maze-solver-part-2-summary/
Privacy Policyhttps://realpython.com/privacy-policy/

Viewport: width=device-width, initial-scale=1, shrink-to-fit=no, viewport-fit=cover

Robots: max-image-preview:large


URLs of crawlers that visited me.