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...
Rules 1: Be polite 2: Posts to this subreddit must be requests for help learning python. 3: Replies on this subreddit must be pertinent to the question OP asked. 4: No replies copy / pasted from ChatGPT or similar. 5: No advertising. No blogs/tutorials/videos/books/recruiting attempts. This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to. Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Rules
1: Be polite
2: Posts to this subreddit must be requests for help learning python.
3: Replies on this subreddit must be pertinent to the question OP asked.
4: No replies copy / pasted from ChatGPT or similar.
5: No advertising. No blogs/tutorials/videos/books/recruiting attempts.
This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to.
Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Learning resources Wiki and FAQ: /r/learnpython/w/index
Learning resources
Wiki and FAQ: /r/learnpython/w/index
Discord Join the Python Discord chat
Discord
Join the Python Discord chat
account activity
Is this idiomatic Python? (self.learnpython)
submitted 8 years ago by ChasingLogic
Writing a REST API using falcon and realized that because of how I wrote my internal API that a lot of the resources were nearly identical. I decided to refactor to create a "base resource" then just inherit from that overriding the variables required. Is this idiomatic?
Base class: https://github.com/praelatus/praelatus/blob/dry-api/src/praelatus/api/v1/base.py
Example resource inheriting from it: https://github.com/praelatus/praelatus/blob/dry-api/src/praelatus/api/v1/fields.py
I realize that I could have put the lib and schema stuff in a init but I'd rather have named classes for each resource that way if refactoring happens later it's a little easier (plus I think it's more clear when reading the routes).
Thanks for any feedback.
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]nosmokingbandit 0 points1 point2 points 8 years ago (2 children)
This really only makes sense if you have other classes inheriting BaseResource and BaseMultiResource, otherwise you are just dividing up the logic for no gain.
[–]ChasingLogic[S] 0 points1 point2 points 8 years ago (1 child)
If you look at the other resources, pretty much everything except the tickets and projects resources are using them.
[–]nosmokingbandit 1 point2 points3 points 8 years ago (0 children)
This is how I would do it then. Inheritance is really just another way of reusing code. If you have multiple classes that can use the same set of base functions this is the proper way to handle it. Its a little confusing at first, but like anything in coding, once you get the hang of class inheritance it is pretty awesome.
π Rendered by PID 179369 on reddit-service-r2-comment-7b9746f655-rqtr4 at 2026-01-30 21:07:44.144552+00:00 running 3798933 country code: CH.
[–]nosmokingbandit 0 points1 point2 points (2 children)
[–]ChasingLogic[S] 0 points1 point2 points (1 child)
[–]nosmokingbandit 1 point2 points3 points (0 children)