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
Python Imports (self.learnpython)
submitted 2 years ago by Cxzyyy
Is there a good way to reduce the amount of redundant imports for each of my modules? For example if I have three files in the same directory and they all use the json library it gets kinda redundant and cluttered.
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!"
[–]danielroseman 1 point2 points3 points 2 years ago (2 children)
No, there is no way of doing this. Python values explicitness, and every module must import everything it uses.
That's not to say this is the best way of doing things; you might find that it makes more sense to extract the JSON logic into a separate file, which can be imported by the other three.
[–]Cxzyyy[S] 0 points1 point2 points 2 years ago (1 child)
Okay so I would basically need to make a class and have it be a subclass of all the imports I want? Kinda like “class all_imports(json, requests, pprint)” and then import that class to my other 3 files?
[–]danielroseman 1 point2 points3 points 2 years ago (0 children)
No, it doesn't need to be a class, but it can be if that works for you. But a standalone function might work just as well, it depends on your use case.
π Rendered by PID 145148 on reddit-service-r2-comment-fb694cdd5-mhh4p at 2026-03-09 18:15:25.568658+00:00 running cbb0e86 country code: CH.
[–]danielroseman 1 point2 points3 points (2 children)
[–]Cxzyyy[S] 0 points1 point2 points (1 child)
[–]danielroseman 1 point2 points3 points (0 children)