Created
November 19, 2023 05:52
-
-
Save demetranadya/21bd3cf6eaee79ab7976e65b3c9cc592 to your computer and use it in GitHub Desktop.
python args
This file contains 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
# Задание | |
# Напишите скрипт, который принимает любое кол-во параметров через произвольное количество пробелов в качестве аргументов и выводит их в той же последовательности на экран, каждый на отдельной строке. | |
# В случае отсутствия параметров скрипт должен выводить «no args». | |
# Пример 1 | |
# Ввод Вывод | |
# python3 solution.py 5 string 1 | |
# 5 | |
# string | |
# 1 | |
# Пример 2 | |
# Ввод Вывод | |
# python3 solution.py | |
# no args | |
import argparse | |
parser = argparse.ArgumentParser() | |
parser.add_argument('arg', nargs='*') | |
print(parser) | |
print("-----") | |
args = parser.parse_args() | |
print(args) | |
if len(args.arg) == 0: | |
print("no args") | |
for i in args.arg: | |
print(i) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment