[pyar] Ayuda: excepción

Sebastian Bassi sbassi en gmail.com
Mar Dic 3 10:43:37 -03 2019


Antes del open("....")
poné un try:
(el open queda en un bloque inicializado por el try)
y luego del open,

except FileNotFoundError:

y en el bloque del except, que hacer en el caso que no encuentre el
archivo, tipo tirar un mensaje y salir del programa o pedir que ingrese el
nombre del archivo de vuelta.

No hace falta importar el error porque está built-in.








On Tue, Dec 3, 2019 at 10:28 AM Federico Brest <federiconbrest at gmail.com>
wrote:

> buen dia gente!
> tengo el siguiente caso: estoy haciendo un script que abra un csv, y
> quiero hacerle una excepcion q agarre cuando el archivo csv no
> exista...algune me puede tirar un centro?
>
> Mando el procedimiento en cuestión:
> def getCuits(filename = 'cuit.csv'):
>     with open('cuit.csv') as csvDataFile:
>         csvReader = csv.reader(csvDataFile)
>         cuits = []
>         for row in csvReader:
>             for col in row:
>                 cuits.append(col.strip())
>         return cuits
>
> gracias!!
>
> --
> *          Ing. Federico N. Brest*
>   Ingeniero en Sistemas de Información
>             Becario Investigador
>      Universidad Tecnológica Nacional
>       Facultad Regional Buenos Aires
>
> “*¿El éxito es la meta? Pienso que no. La meta es conseguir, defender y
> mantener nuestra libertad*” - Richard Stallman
> *P* *Antes de imprimir este mensaje, piense si realmente es necesario.
> ¡Cuidemos nuestro Ambiente!*
> _______________________________________________
> Lista de Correo de PyAr - Python Argentina - pyar at python.org.ar
> Sitio web: http://www.python.org.ar/
>
> Para administrar la lista (o desuscribirse) entrar a
> http://listas.python.org.ar/listinfo/pyar
>
> La lista de PyAr esta Hosteada en USLA - Usuarios de Software Libre de
> Argentina - http://www.usla.org.ar



-- 


Non standard disclaimer: READ CAREFULLY. By reading this email,
you agree, on behalf of your employer, to release me from all
obligations and waivers arising from any and all NON-NEGOTIATED
agreements, licenses, terms-of-service, shrinkwrap, clickwrap,
browsewrap, confidentiality, non-disclosure, non-compete and
acceptable use policies ("BOGUS AGREEMENTS") that I have
entered into with your employer, its partners, licensors, agents and
assigns, in perpetuity, without prejudice to my ongoing rights and
privileges. You further represent that you have the authority to release
me from any BOGUS AGREEMENTS on behalf of your employer.
Google ads remover words: suicide, murder
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.python.org.ar/pipermail/pyar/attachments/20191203/f7729ad5/attachment.html>


Más información sobre la lista de distribución pyar