forked from rctorr/PythonMexico
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhola-0.4.py
More file actions
executable file
·41 lines (34 loc) · 1.12 KB
/
hola-0.4.py
File metadata and controls
executable file
·41 lines (34 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Aquí se importan módulos o librerías
import sys
def help():
""" Imprime la ayuda del script en la salida estándar """
print("""
Sintaxis:
hola.py [--help] tuNombre
Imprime en la salida estándar el saludo incluyendo tuNombre
Opciones:
--help Imprime en la salida estándar esta ayuda
""")
# Se define una función, en este caso la función main(), aunque en
# Python no es necesaria se usa y define por convención y organización
# del código.
def main(argv):
""" Función principal del script """
# Verificamos si tenemos tenemos un argumento
if len(argv) < 2:
# No tenemos datos para continuar, enviamos la ayuda
help()
# Terminamos el script
sys.exit(0)
# Buscamos la opción --help
if "--" in argv[1]:
help()
sys.exit(0)
# Si llegamos hasta aquí, entonces tenemos datos para continuar
print(("Hola {}!".format(argv[1])).upper())
# Este if permite usar este script como un comando desde el shell o
# como un módulo desde otro script en Python.
if __name__ == "__main__":
main(sys.argv)