GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — Hello-Python/Hello-Python/Basic/hello_module.py at main · mrtngrsbch/Hello-Python Expand file tree/ Copy pathhello_module.pyMore file actions 40 lines (29 loc) · 1.13 KB / Copy pathhello_module.pyFile metadata and controls40 lines (29 loc) · 1.13 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 """ Módulo simple para Clase 01: funciones reutilizables y ejecutable como script. - hello(): devuelve un saludo estándar (puro, fácil de testear) - greet(name): valida la entrada y devuelve un saludo personalizado Ejecutar como script: ../.venv/bin/python Hello-Python/Basic/hello_module.py [nombre] """ import sys def hello() -> str: """Devuelve un saludo básico. Uso: pensado para ser llamado desde tests o desde main. """ return "Hola Python" def greet(name: str) -> str: """Devuelve un saludo personalizado validando la entrada. - Rechaza valores no str o cadenas vacías/solo espacios - Normaliza espacios usando strip() - No imprime: devuelve el resultado (más fácil de testear) """ if not isinstance(name, str) or not name.strip(): raise ValueError("name debe ser un string no vacío") return f"Encantado, {name.strip()}!" if __name__ == "__main__": # Permite ejecutar el archivo directamente desde la terminal: # ../.venv/bin/python Hello-Python/Basic/hello_module.py [nombre] if len(sys.argv) > 1: print(greet(sys.argv[1])) else: print(hello()) |
| You are visitor 01402520 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |