I know where to register them, but how to use them or call them in the program itself?
1 answer
Through the array sys.argv . For example:
if len( sys.argv ) != 2: print "invalid arguments" exit ( 1 ) firstArg = sys.argv[ 1 ] You can also use for example the click library, an example from an offsite:
import click @click.command() @click.option('--count', default=1, help='Number of greetings.') @click.option('--name', prompt='Your name', help='The person to greet.') def hello(count, name): """Simple program that greets NAME for a total of COUNT times.""" for x in range(count): click.echo('Hello %s!' % name) if __name__ == '__main__': hello() There are all sorts of buns out of the box, such as opening a file, checking paths, etc.
- if I enter sys.argv in PyCharm, then the environment complains about an error in this line. import sys also can not do, the environment does not allow. - Yevgeny Efimenko
- @YevgenyEfimenko Yes, of course, you need to import the
sysmodule. Just what does the environment not allow? - Vladimir Gamalyan - When I prescribe import sys, the environment does not accept it, it is gray, it always reacts to this line - Yevgeny Efimenko
- if I am not mistaken, in gray pycharm highlights unused imports, i.e. if you write
import sys, and then do not usesysanywhere, you will get the selection in gray. - Vladimir Gamalyan
|