Last active
February 26, 2023 21:08
-
-
Save eder-projetos-dev/aac4ef7d8319d26a0b7fe027be06b62a to your computer and use it in GitHub Desktop.
Python - Lendo a lista de argumentos passados para o script
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
import sys | |
try: | |
if sys.argv[1] in sys.argv: # Caso exista argumento 1 | |
match sys.argv[1]: | |
case "oi": | |
print("\nOlá pessoa!") | |
case "tchau": | |
print("\nTchau, até logo!") | |
case _: | |
print("\nAs opções válidas são: oi e tchau\n") | |
except IndexError: | |
# Se não existir argumento 1 | |
print("\nDigite oi ou tchau conforme o exemplo abaixo:") | |
print("\npython passando_argumentos.py oi") | |
finally: | |
print("\nExemplo de como ler argumentos passados pelo shell\n") |
Author
eder-projetos-dev
commented
Jan 31, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment