Created
July 4, 2020 01:57
-
-
Save sahara-ooga/3158e3cf5eb2b2541e5caa4a83d6bd5a to your computer and use it in GitHub Desktop.
Pythonでコマンドライン引数を受け取る
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
def main_args(): | |
args = sys.argv # args[0]はファイル名 | |
print(args) | |
print(len(args)) | |
print("第1引数:" + args[1]) | |
print("第2引数:" + args[2]) | |
print("第3引数:" + args[3]) | |
if __name__ == "__main__": | |
main_args() | |
""" | |
% python main-arg.py a b c | |
['main-arg.py', 'a', 'b', 'c'] | |
4 | |
第1引数:a | |
第2引数:b | |
第3引数:c | |
""" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment