Skip to content

Instantly share code, notes, and snippets.

@eder-projetos-dev
Last active February 26, 2023 21:08
Show Gist options
  • Save eder-projetos-dev/aac4ef7d8319d26a0b7fe027be06b62a to your computer and use it in GitHub Desktop.
Save eder-projetos-dev/aac4ef7d8319d26a0b7fe027be06b62a to your computer and use it in GitHub Desktop.
Python - Lendo a lista de argumentos passados para o script
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")
@eder-projetos-dev
Copy link
Author

saida

@eder-projetos-dev
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment