PyWombat

Lectura de argumentos

Nuevo tip

La forma más simple de obtener y procesar los argumentos de la línea de comandos es utilizando el atributo argv del módulo sys.

#main.py
import sys

if __name__ == '__main__':
    print(f"The first argument:  '{sys.argv[0]}'")
    print(f"The second argument: '{sys.argv[1]}'")
    print(f"The third argument:  '{sys.argv[2]}'")
    print(f"The fourth argument: '{sys.argv[3]}'")

Ejecución.

$ python main.py Nuevo Tip PyWombat
The first argument:  'main.py'
The second argument: 'Nuevo'
The third argument:  'Tip'
The fourth argument: 'PyWombat'