René's URL Explorer Experiment


Title: Load the Maze From a Binary File (Video) – Real Python

Open Graph Title: Load the Maze From a Binary File – Real Python

Description: Load the Maze From a Binary File. After completing part one of this course, you can build and draw the maze. However, creating it by hand in Python takes a lot of error-prone and tedious effort. By the end of this step, you’ll have a custom file…

Open Graph Description: Load the Maze From a Binary File. After completing part one of this course, you can build and draw the maze. However, creating it by hand in Python takes a lot of error-prone and tedious effort. By the end of this step, you’ll have a custom file…

Opengraph URL: https://realpython.com/videos/python-maze-binary-file/

X: @realpython

direct link

Domain: realpython.com


Hey, it has json ld scripts:
  {
    "@context": "https://schema.org",
    "@type": "VideoObject",
    "name": "Load the Maze From a Binary File",
    "description": "Load the Maze From a Binary File. After completing part one of this course, you can build and draw the maze. However, creating it by hand in Python takes a lot of error\u002Dprone and tedious effort. By the end of this step, you’ll have a custom file…",
    "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": "PT4M55S",
    "embedUrl": "https://realpython.com/videos/python-maze-binary-file/embed/",
    "potentialAction": {
      "@type": "SeekToAction",
      "target": "https://realpython.com/videos/python-maze-binary-file/#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/videos/python-maze-binary-file/
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/videos/python-maze-binary-file/
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=%2Fvideos%2Fpython-maze-binary-file%2F
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/videos/python-maze-binary-file/#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/videos/python-maze-binary-file/#description
Transcripthttps://realpython.com/videos/python-maze-binary-file/#transcript
Discussionhttps://realpython.com/videos/python-maze-binary-file/#discussion
00:00https://realpython.com/videos/python-maze-binary-file/#t=0.53
Load the Maze From a Binary File.https://realpython.com/videos/python-maze-binary-file/#t=0.53
After completing part one of this course, you can build and draw the maze.https://realpython.com/videos/python-maze-binary-file/#t=3.9699999999999998
However,https://realpython.com/videos/python-maze-binary-file/#t=8.23
creating it by hand in Python takes a lot of error-prone and tedious effort.https://realpython.com/videos/python-maze-binary-file/#t=9.2
00:13https://realpython.com/videos/python-maze-binary-file/#t=13.8
By the end of this step,https://realpython.com/videos/python-maze-binary-file/#t=13.8
you’ll have a custom file format for the persistent storage of mazes,https://realpython.com/videos/python-maze-binary-file/#t=14.74
which you’ll be able to save and load at the push of a button.https://realpython.com/videos/python-maze-binary-file/#t=18.47
00:22https://realpython.com/videos/python-maze-binary-file/#t=22.029
Besides that,https://realpython.com/videos/python-maze-binary-file/#t=22.029
you’ll also be able to load the sample mazes supplied with the course materials.https://realpython.com/videos/python-maze-binary-file/#t=22.96
Squares in the maze are very much like pixels in an image.https://realpython.com/videos/python-maze-binary-file/#t=29.61
00:33https://realpython.com/videos/python-maze-binary-file/#t=33.28
One of the sample mazes included in the supporting materials has several hundredhttps://realpython.com/videos/python-maze-binary-file/#t=33.28
of them,https://realpython.com/videos/python-maze-binary-file/#t=37.02
but you could very easily be looking at thousands of squares in some largerhttps://realpython.com/videos/python-maze-binary-file/#t=37.64
mazes.https://realpython.com/videos/python-maze-binary-file/#t=41.55
00:41https://realpython.com/videos/python-maze-binary-file/#t=41.94
If you were to represent the squares as text,https://realpython.com/videos/python-maze-binary-file/#t=41.94
then they would quickly amount to a huge file size.https://realpython.com/videos/python-maze-binary-file/#t=44.65
Given that you already devised a compact representation for border patterns thathttps://realpython.com/videos/python-maze-binary-file/#t=48.12
leverages a bit field, it makes perfect sense to define a binary file formathttps://realpython.com/videos/python-maze-binary-file/#t=52.19
instead.https://realpython.com/videos/python-maze-binary-file/#t=56.34
00:57https://realpython.com/videos/python-maze-binary-file/#t=57.316
When defining a binary file format,https://realpython.com/videos/python-maze-binary-file/#t=57.316
the first thing you need to decide on is whether you’ll store values that canhttps://realpython.com/videos/python-maze-binary-file/#t=61.72
fit in a single byte or more.https://realpython.com/videos/python-maze-binary-file/#t=65.32
The reason is that different computer architectures have different endianness,https://realpython.com/videos/python-maze-binary-file/#t=67.72
which is a fancy way of saying that they read a sequence of bytes in thehttps://realpython.com/videos/python-maze-binary-file/#t=71.99
opposite order.https://realpython.com/videos/python-maze-binary-file/#t=75.38
01:16https://realpython.com/videos/python-maze-binary-file/#t=76.5
Thehttps://realpython.com/videos/python-maze-binary-file/#t=76.5
two standards for byte order are called big-endian and little-endian.https://realpython.com/videos/python-maze-binary-file/#t=78.53
In big-endian, the most significant byte comes first, while in little-endian,https://realpython.com/videos/python-maze-binary-file/#t=83.49
the least significant byte comes first.https://realpython.com/videos/python-maze-binary-file/#t=88.33
01:33https://realpython.com/videos/python-maze-binary-file/#t=93.01
If you wrote a numeric value using one standard, but read it with another,https://realpython.com/videos/python-maze-binary-file/#t=93.01
then you’ll get a garbled result,https://realpython.com/videos/python-maze-binary-file/#t=96.58
just as if you applied the wrong character encoding.https://realpython.com/videos/python-maze-binary-file/#t=98.26
01:44https://realpython.com/videos/python-maze-binary-file/#t=104.46
You are going to need more than one byte to store values like the width orhttps://realpython.com/videos/python-maze-binary-file/#t=104.46
height of the maze, which can be far greater than the maximum byte value of 255.https://realpython.com/videos/python-maze-binary-file/#t=108.0
01:53https://realpython.com/videos/python-maze-binary-file/#t=113.32
Because many popular file formats stick with a little-endian standard,https://realpython.com/videos/python-maze-binary-file/#t=113.32
so will you.https://realpython.com/videos/python-maze-binary-file/#t=117.07
Binary files often begin with a fixed sequence of bytes to uniquely identifyhttps://realpython.com/videos/python-maze-binary-file/#t=120.43
their particular format.https://realpython.com/videos/python-maze-binary-file/#t=124.43
02:06https://realpython.com/videos/python-maze-binary-file/#t=126.114
For example,https://realpython.com/videos/python-maze-binary-file/#t=126.114
Java’s class files always start with the four bytes seen on-screen,https://realpython.com/videos/python-maze-binary-file/#t=127.45
which is one of the geeky references to coffee in the language’s vast ecosystem.https://realpython.com/videos/python-maze-binary-file/#t=130.96
02:16https://realpython.com/videos/python-maze-binary-file/#t=136.45
Such an initial value is known as the magic number,https://realpython.com/videos/python-maze-binary-file/#t=136.45
although it can sometimes be textual.https://realpython.com/videos/python-maze-binary-file/#t=139.38
02:24https://realpython.com/videos/python-maze-binary-file/#t=144.06
Tools like the Unix file command leverage known magic numbers to detect filehttps://realpython.com/videos/python-maze-binary-file/#t=144.06
types.https://realpython.com/videos/python-maze-binary-file/#t=148.41
In this case,https://realpython.com/videos/python-maze-binary-file/#t=149.893
the tool correctly recognized an SVG graphics filehttps://realpython.com/videos/python-maze-binary-file/#t=153.12
02:39https://realpython.com/videos/python-maze-binary-file/#t=159.18
and the contents of a TOML file as ASCII text.https://realpython.com/videos/python-maze-binary-file/#t=159.18
02:46https://realpython.com/videos/python-maze-binary-file/#t=166.28
You can choose any magic number for your custom maze file format,https://realpython.com/videos/python-maze-binary-file/#t=166.28
but in this course you’ll use the four ASCII characters MAZE in uppercase.https://realpython.com/videos/python-maze-binary-file/#t=169.48
02:54https://realpython.com/videos/python-maze-binary-file/#t=174.45
The hexadecimal representation seen on screen looks less coffee-like,https://realpython.com/videos/python-maze-binary-file/#t=174.45
but it’s just as unique and recognizable.https://realpython.com/videos/python-maze-binary-file/#t=178.85
The magic number is usually followed by a file header,https://realpython.com/videos/python-maze-binary-file/#t=181.95
which provides useful metadata about the actual data in the file.https://realpython.com/videos/python-maze-binary-file/#t=185.09
03:09https://realpython.com/videos/python-maze-binary-file/#t=189.68
The header has a fixed structure consisting of fields, such as the width of thehttps://realpython.com/videos/python-maze-binary-file/#t=189.68
maze.https://realpython.com/videos/python-maze-binary-file/#t=193.45
However, the header may have a variable length—for example,https://realpython.com/videos/python-maze-binary-file/#t=193.869
due to enemy positions kept in the lookup table or other optional fields.https://realpython.com/videos/python-maze-binary-file/#t=198.32
03:25https://realpython.com/videos/python-maze-binary-file/#t=205.14
If you foresee introducing breaking changes to your file format in the future—https://realpython.com/videos/python-maze-binary-file/#t=205.14
for example, due to new features—https://realpython.com/videos/python-maze-binary-file/#t=209.3
then you should consider including a version field either at the beginning orhttps://realpython.com/videos/python-maze-binary-file/#t=211.11
before the header.https://realpython.com/videos/python-maze-binary-file/#t=214.76
03:36https://realpython.com/videos/python-maze-binary-file/#t=216.77
This should enable you to handle slight differences across file format versions.https://realpython.com/videos/python-maze-binary-file/#t=216.77
Each header field must have a known type, size, and offset measured in bytes sincehttps://realpython.com/videos/python-maze-binary-file/#t=223.61
the beginning of the file, so you know where the next field begins.https://realpython.com/videos/python-maze-binary-file/#t=228.34
03:52https://realpython.com/videos/python-maze-binary-file/#t=232.49
The maze header file will have the three fields seen on-screen.https://realpython.com/videos/python-maze-binary-file/#t=232.49
The first field is a single byte with the file format version,https://realpython.com/videos/python-maze-binary-file/#t=236.21
which you may increment by one with each new release.https://realpython.com/videos/python-maze-binary-file/#t=239.56
04:03https://realpython.com/videos/python-maze-binary-file/#t=243.33
Notice that the version field starts with an offset of four bytes because thehttps://realpython.com/videos/python-maze-binary-file/#t=243.33
magic number occupies the first four bytes in the file.https://realpython.com/videos/python-maze-binary-file/#t=246.95
The other two fields are unsigned integers taking up four bytes each,https://realpython.com/videos/python-maze-binary-file/#t=250.89
which means they can have values between zero and over four billion,https://realpython.com/videos/python-maze-binary-file/#t=254.19
which should be enough for anybody.https://realpython.com/videos/python-maze-binary-file/#t=257.68
04:22https://realpython.com/videos/python-maze-binary-file/#t=262.56
Once you get through the header and have complete information about the amounthttps://realpython.com/videos/python-maze-binary-file/#t=262.56
and layout of the data, you may start reading the file body,https://realpython.com/videos/python-maze-binary-file/#t=265.95
which is the main part of the file.https://realpython.com/videos/python-maze-binary-file/#t=269.29
04:31https://realpython.com/videos/python-maze-binary-file/#t=271.288
It’s where you’ll find most of your data,https://realpython.com/videos/python-maze-binary-file/#t=271.288
and in this case,https://realpython.com/videos/python-maze-binary-file/#t=273.92
the body will be a very long one-dimensional array of numbers representing thehttps://realpython.com/videos/python-maze-binary-file/#t=274.76
various border patterns around the squares and their roles.https://realpython.com/videos/python-maze-binary-file/#t=278.94
04:44https://realpython.com/videos/python-maze-binary-file/#t=284.95
Now that you’ve seen how the maze data can be represented in a binary file,https://realpython.com/videos/python-maze-binary-file/#t=284.95
in the next section you’ll look into packing the data of the file body using ashttps://realpython.com/videos/python-maze-binary-file/#t=288.47
few bytes as possible.https://realpython.com/videos/python-maze-binary-file/#t=292.43
Become a Memberhttps://realpython.com/account/join/
https://realpython.com/videos/python-maze-solver-part-2-overview/
Overviewhttps://realpython.com/courses/python-maze-solver/
https://realpython.com/videos/python-maze-data-alignment/
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.