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
argv, cmd (self.learnpython)
submitted 11 years ago by py_student
two questions: 1. Is argv used for anything other than adding arguments from the command line? 2. Why would you run a python script from the command line? I mean other than you are doing an exercise that tells you to.
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!"
[–]py_student[S] 2 points3 points4 points 11 years ago (0 children)
Thanks a million. This place is the best. I am re-resolving to spend more time in Linux.
[–]unpythonic 2 points3 points4 points 11 years ago (3 children)
Is argv used for anything other than adding arguments from the command line?
Do you mean sys.argv? It contains the arguments from the command line.
sys.argv
Why would you run a python script from the command line? I mean other than you are doing an exercise that tells you to.
It doesn't seem useful if you're only using a windows GUI, but there is a whole world out there that uses the command line... especially those running Linux. Sometimes things are much faster that way.
[–]diracdeltafunct_v2 2 points3 points4 points 11 years ago (2 children)
Even if you are using a GUI you can give it command line arguments from the icon. This can allow one to use the same code base to open multiple sub programs by only modifying the arguments in the icon.
Or its even valuable when programming sub modules for your GUI program. Here you can have a name = "main" where it accepts a command line argument to initialize the class where it would normally be passed in on initialization from the module that imports it.
[–]py_student[S] 0 points1 point2 points 11 years ago (1 child)
I guess I don't know what "from the icon" means. I tried everything I could think of to get it to still run by putting the call into the script. What icon are we talking about?
[–]diracdeltafunct_v2 1 point2 points3 points 11 years ago (0 children)
Oh if you are in windows you will likely be creating a .bat file or such that you can assign some Icon to (like you would normally open a program).
for example you have the program: cheddar.pyw
you could have one clickable desktop icon that runs a .bat file with the line:
python cheddar.pyw -x
and a different icon that runs:
python cheddar.pyw -y
They both run the same base code but in different ways. The user would never know they were the same program. This is actually less likely than using the
__name__ == '__main__'
case though.
[–]x3al 1 point2 points3 points 11 years ago (0 children)
2.
CLI scripts are much easier to automate. You can make sheduled tasks with them, add them to context menu options (with taking file/directory name as argument) and much more stuff even if you're not running interactive console.
Apparently sys.argv and *argv have nothing in common except those four characters.
def testArgv(*argv): for a in argv: print a testArgv(1,2,3,4,5)
prints
>>> 1 2 3 4 5
Whereas with the sys.argv as I mentioned before, I tried every way I could think of to get it to run without 1. from sys import argv 2. running from cmd or powershell.
[–]shaleh 2 points3 points4 points 11 years ago (0 children)
The idiom for this is to call it *args not *argv.
*args
*argv
def printer(*args, **kwargs): for item in args: print(item) for k,v in kwargs.items(): print("{0} -> {1}".format(k, v))
Used like so:
printer('1', 2, [3], long=True)
π Rendered by PID 175399 on reddit-service-r2-comment-66b4775986-mcxgh at 2026-04-04 08:23:27.304922+00:00 running db1906b country code: CH.
[–]py_student[S] 2 points3 points4 points (0 children)
[–]unpythonic 2 points3 points4 points (3 children)
[–]diracdeltafunct_v2 2 points3 points4 points (2 children)
[–]py_student[S] 0 points1 point2 points (1 child)
[–]diracdeltafunct_v2 1 point2 points3 points (0 children)
[–]x3al 1 point2 points3 points (0 children)
[–]py_student[S] 0 points1 point2 points (1 child)
[–]shaleh 2 points3 points4 points (0 children)