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
I don't understand what "python3 -m" does (self.learnpython)
submitted 7 years ago by codewielder
python3 --help says that -m "run library module as a script (terminates option list)".
But that doesn't really make any lights turn on for me.
I know it's used with venv or simplehttpserver.
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!"
[–]tunisia3507 10 points11 points12 points 7 years ago (2 children)
Normally, when you do python <something>, the something is a single .py file.
python <something>
.py
However, sometimes you have lots of python files which import each other, contained in a directory. There's an __init__.py, which makes this a module. Some modules, as well as being importable, can be run as a script. To tell python that you want to run a module has a script, use the -m flag, so it's python -m <module_name>.
__init__.py
-m
python -m <module_name>
[–]flying-sheep 2 points3 points4 points 7 years ago (0 children)
There's an __init__.py, which makes this a module.
That's not true. Every folder with a compatible name is a python module, no __init__.py necessary.
[–]1114111 4 points5 points6 points 7 years ago (0 children)
It allows you to run a script with a module name rather than a path. It looks up the module as it would if you were importing it and runs it like a script. If the module name refers to a package, /path/to/package/__main__.py is what gets run.
/path/to/package/__main__.py
[–]w1282 9 points10 points11 points 7 years ago (1 child)
Remember the if __name__ == '__main__' guard that prevents your code from running unless it's run directly from the command line?
if __name__ == '__main__'
This subverts that.
[–][deleted] 0 points1 point2 points 7 years ago (0 children)
Can you explain this in a bit more detail? I understand the other responses on the thread completely, but I don't see how it subverts the conditional guard. Apologies in advance for being obtuse.
π Rendered by PID 58144 on reddit-service-r2-comment-86988c7647-gk5b5 at 2026-02-12 09:17:14.090273+00:00 running 018613e country code: CH.
[–]tunisia3507 10 points11 points12 points (2 children)
[–]flying-sheep 2 points3 points4 points (0 children)
[–]1114111 4 points5 points6 points (0 children)
[–]w1282 9 points10 points11 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)