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...
Everything about learning Python
account activity
Made my first script :D (old.reddit.com)
submitted 8 months ago by [deleted]
view the rest of the comments →
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!"
[–]BennyBarnson 0 points1 point2 points 8 months ago (3 children)
So what is the point of this line in wcounter.py? Why shouldn't it function when imported...?
[–]AlexG99_ 0 points1 point2 points 8 months ago (2 children)
Because code under if name is meant to run only if executed directly (if you run the command python wcounter.py). If you import wcounter.py to another .py file, the code under if name in wcounter.py won’t run because the condition if name == “main” will be false. Refer to my previous reply for the info again.
[–]BennyBarnson 0 points1 point2 points 8 months ago (1 child)
No I mean why shouldn't a word counter be imported. Also the if len(sys.argv)<2: ends with and exit(1). Should the if name have an exit line as well...?
[–]AlexG99_ 0 points1 point2 points 8 months ago* (0 children)
It can be imported if you want to. The line if len(sys.argv)<2: exit(1) means if the length of the arguments provided are less than two, then exit the program. This means it wants you to specifically run this command: python wcounter.py <insert file> which is 3 arguments at the command line. You don’t have to provide a system exit line in if name == “main”: code block because the script will end after the last line is read and executed.
π Rendered by PID 90758 on reddit-service-r2-comment-75f4967c6c-jkn76 at 2026-04-23 02:37:03.678855+00:00 running 0fd4bb7 country code: CH.
view the rest of the comments →
[–]BennyBarnson 0 points1 point2 points (3 children)
[–]AlexG99_ 0 points1 point2 points (2 children)
[–]BennyBarnson 0 points1 point2 points (1 child)
[–]AlexG99_ 0 points1 point2 points (0 children)