[Tutor] Write new line(enter) in txt

Joel Goldstick joel.goldstick at gmail.com
Mon Mar 28 17:21:39 CEST 2011


On Mon, Mar 28, 2011 at 11:12 AM, Susana Iraiis Delgado Rodriguez <
susana.delgado_s at utzmg.edu.mx> wrote:

> Hello list!!
>
> This is a very simple question!! I want to write some lines in a txt file,
> but my output looks like this:
> No existe el archivo C:\índice.dbfNo existe el archivo C:\índice_dwg.dbfNo
> existe el archivo C:\índice_raster.dbf
> I need it to look like this:
> No existe el archivo C:\índice.dbf
> No existe el archivo C:\índice_dwg.dbf
> No existe el archivo C:\índice_raster.dbf
>
> The code I wrote is:
> log = open ('errors.txt','wb')
> shp = 'Error al abrir el archivo' +filepath
> log.write(shp+"\n")
> n = os.path.splitext(filepath)
> p = n[0]+'.prj'
> shx = n[0]+'.shx'
> dbf = n[0]+'.dbf'
> if os.path.exists(shx):
>                         print 'El archivo ' +shx +' existe'
>                 else:
>                         log.write('No existe el archivo ' +shx+"\n")
>                 if os.path.exists(dbf):
>                         print 'El archivo ' +dbf +' existe'
>                 else:
>                         log.write('No existe el archivo ' +dbf+"\n")
> log.close()
>
>
> Windows systems I believe need cr/lf for end of line character.  You should
first try opening your file in text mode, not binary.  Then your \n will be
translated into whatever end of line sequence your operating system
requires.


http://docs.python.org/tutorial/inputoutput.html#reading-and-writing-files


> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>


-- 
Joel Goldstick
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110328/56f4451c/attachment-0001.html>


More information about the Tutor mailing list