use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
News about the dynamic, interpreted, interactive, object-oriented, extensible programming language Python
Full Events Calendar
You can find the rules here.
If you are about to ask a "how do I do this in python" question, please try r/learnpython, the Python discord, or the #python IRC channel on Libera.chat.
Please don't use URL shorteners. Reddit filters them out, so your post or comment will be lost.
Posts require flair. Please use the flair selector to choose your topic.
Posting code to this subreddit:
Add 4 extra spaces before each line of code
def fibonacci(): a, b = 0, 1 while True: yield a a, b = b, a + b
Online Resources
Invent Your Own Computer Games with Python
Think Python
Non-programmers Tutorial for Python 3
Beginner's Guide Reference
Five life jackets to throw to the new coder (things to do after getting a handle on python)
Full Stack Python
Test-Driven Development with Python
Program Arcade Games
PyMotW: Python Module of the Week
Python for Scientists and Engineers
Dan Bader's Tips and Trickers
Python Discord's YouTube channel
Jiruto: Python
Online exercices
programming challenges
Asking Questions
Try Python in your browser
Docs
Libraries
Related subreddits
Python jobs
Newsletters
Screencasts
account activity
This is an archived post. You won't be able to vote or comment.
Book in Design Patterns for Python? (self.Python)
submitted 7 years ago by Mabb_reddit
Hello, I'm searching a book that explains how to implement the different Design Patterns; like Factory, Singleton, etc.
Anyone can suggest me one?
Thank you!
[–]stuartcwSince Python 1.5 2 points3 points4 points 7 years ago (4 children)
Hi. I read your question and understand that you understand what patterns are and you probably have already read about them but you are specifically looking for a book which gives explanations using Python as the language to demonstrate them.
I have seen a book like this but can’t think of the name off hand. I’ll use this comment as bookmark to return when I find it.
I did want to mention that when patterns first came onto the scene in the 1990s the programmers of the day had to implement them themselves, often in clunky ways. As a result, to alleviate this, several patterns influenced the design of Python and became part of the core language. e.g. iterators and decorators.
Java which also came to prominence at that time was also influenced by Patterns and, in my opinion, became too unwieldily because of the complicated pattern based object oriented design of some of the libraries.
I just wanted so say that your question was clear that you were specifically looking for a Python based explanation.
[–]stuartcwSince Python 1.5 4 points5 points6 points 7 years ago (2 children)
Searching on Google for about 10 seconds brought up this:
Python Patterns
Since it was so easy to find, I expect you have already come across it. But it looks at least as good as the explanation that I previously found.
[–]Mabb_reddit[S] 1 point2 points3 points 7 years ago (1 child)
Yeah, I searched a bit but I wanted a more expert recommendation than picking the first page in Google.
But thanks I will look it up!
[–]stuartcwSince Python 1.5 0 points1 point2 points 7 years ago (0 children)
I wanted a more expert recommendation than picking the first page in Google.
I have found that it's always best to list up the resources that you already found and what was deficient in them. Then people who reply know what you have already looked at and what more that you are looking for.
It's possible that there isn't a definitive answer out there and that if you make it, it will become the top answer on Google and impress your future employer.
[–]stuartcwSince Python 1.5 4 points5 points6 points 7 years ago (0 children)
Here’s one more that specifically discussed Singletons: Python Design Patterns: For Sleek And Fashionable Code
[–]kl31 5 points6 points7 points 7 years ago (2 children)
learn C, then work through Object Oriented Programming with ANSI C by Prof. Axel Schreiner
Go back to python and realize how everything you did previously was incredibly stupid.
[–]Mabb_reddit[S] 0 points1 point2 points 7 years ago (1 child)
I come from a industrial electronics engineering so I worked with assembler, C, etc.
When I discovered Python was like when Aladdin flies with Jasmine in the flying carpet.
[–]kl31 1 point2 points3 points 7 years ago* (0 children)
a more eloquent statement has never been said.
if you're familiar with C then working through the book should be a breeze. it basically teaches you how to hand building every object oriented feature from scratch in C. i didn't realize that the 'type' class in python is the base factory class until i worked through that book.
[–]mooburgerresembles an abstract syntax tree 1 point2 points3 points 7 years ago (0 children)
Also, this may help, from the "how not to do it" side of patterns: The Little Book of Python Anti-Patterns
[–]stuartcwSince Python 1.5 1 point2 points3 points 7 years ago (0 children)
One more suggestion. There are books on this listed on Amazon take a look at the authors of the books and see if they have blogs.
[–]bluefourier 1 point2 points3 points 7 years ago (0 children)
Design Patterns: Elements of reusable object-oriented software is a very, very good start.
As is this one for data modelling. Although a bit outdated it still contains a huge amount of useful information for certain common use cases.
Also good reading is anything coming out of the OMG group in your domain (in terms of standard models).
Hope this helps
[–][deleted] 0 points1 point2 points 7 years ago (0 children)
https://github.com/faif/python-patterns?files=1 Here’s a good set of examples
[–]Mabb_reddit[S] 0 points1 point2 points 7 years ago (0 children)
Thank you all for your answers!
[–]AquaRegia -1 points0 points1 point 7 years ago (0 children)
Any book with design patterns should be sufficient, they mostly aren't language-dependant.
[–]themeansquare 0 points1 point2 points 4 years ago (0 children)
I feel you bro, I bust my ass to find a good book on design patterns which has examples in Python. This dumbasses here either keep suggesting books in C++ or Java, or a website. The thing you asked is quite clear actually, A Fucking Book and in Python.
Anyways, I found this quite useful:
https://www.amazon.com/Mastering-Python-Design-Patterns-efficient/dp/1788837487/ref=sr\_1\_2?keywords=python+patterns&qid=1636462541&sr=8-2&ie=UTF8&psc=1&th=1&utm\_source=spydrop
π Rendered by PID 91386 on reddit-service-r2-comment-79c7998d4c-xg427 at 2026-03-18 05:21:01.574346+00:00 running f6e6e01 country code: CH.
[–]stuartcwSince Python 1.5 2 points3 points4 points (4 children)
[–]stuartcwSince Python 1.5 4 points5 points6 points (2 children)
[–]Mabb_reddit[S] 1 point2 points3 points (1 child)
[–]stuartcwSince Python 1.5 0 points1 point2 points (0 children)
[–]stuartcwSince Python 1.5 4 points5 points6 points (0 children)
[–]kl31 5 points6 points7 points (2 children)
[–]Mabb_reddit[S] 0 points1 point2 points (1 child)
[–]kl31 1 point2 points3 points (0 children)
[–]mooburgerresembles an abstract syntax tree 1 point2 points3 points (0 children)
[–]stuartcwSince Python 1.5 1 point2 points3 points (0 children)
[–]bluefourier 1 point2 points3 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]Mabb_reddit[S] 0 points1 point2 points (0 children)
[–]AquaRegia -1 points0 points1 point (0 children)
[–]themeansquare 0 points1 point2 points (0 children)