Locked learning resources

Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Locked learning resources

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Bringing It All Together and Reading GitHub Issue Comments

Written tutorial for more details: https://realpython.com/structural-pattern-matching/

00:00 Now bring it all together in the main function. def main(): events = fetch_github_events( "python", "cpython")

00:14 For comment in filter_comments(events):

00:20 print("nnn") print( comment) input( `”Press Enter for the next comment.”)

00:35 If __name__ == "__main__": run_main(). First, you fetch the events, then you iterate over the results of passing events to filter_comments().

00:49 Each comment will be your nicely formatted template string. Print a few new lines to provide a little extra spacing and print the comment. Finally, display a message telling the user they can view the next comment by hitting the Enter key.

01:02 Then you use the name main guard to ensure main() only runs when Python runs this script directly. Now give it a whirl,

01:15 and expand the window. And here’s our first comment. Hit Enter. We can see a second comment. Enter again. And one more comment, you can keep hitting Enter until you run out of comments returned from the API. And because this is a live API, the comments you see will probably be different than the comments I’m seeing.

01:38 And this is just the start. Here’s an example of taking this concept to the next level, using the Rich library. Close this.

01:50 Here’s that same first comment now in a much nicer Markdown format. Same second comment, and same third comment. Much nicer, right? If you’re interested, check out the written tutorial that this course is based on where all of this code is fleshed out in detail.

02:07 Okay. Structural pattern matching is awesome and you should use it for everything, right? Mm, maybe not. Let’s cap things off with an exploration of pattern matching’s limitations and common pitfalls.

Become a Member to join the conversation.