Python Forum
Manipulating files Python 2.7
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Manipulating files Python 2.7
#3
Thanks to the tips. I thought like you, my dificulty it's the python. So, i'm create a program and works. Thanks awnser me!

def dger_ano(FILE_DATE, ORIGEM, DESTINO):
    cache = None
    string = "ANO INICIO DO ESTUDO 2016"  #str(int(FILE_DATE) - 1)
    with open(ORIGEM , "r") as f: cache = f.read()
    new_file = re.sub(string, "ANO INICIO DO ESTUDO {}".format(FILE_DATE), cache)
    if new_file:
        with open(DESTINO + "/temporario.txt", "w") as f: f.write(new_file)
    os.remove(DESTINO + "/DGER.dat")
    os.rename(DESTINO + '/temporario.txt',DESTINO + '/DGER.dat')
In Python 2 : has the accent on the file appears this error message, "UnicodeDecodeError: 'ascii' codec can't decode byte 0xba in position 1355: ordinal not in range(128) "
Python 3 : Works!

BUT, i need to work on Python 2
Reply


Messages In This Thread
Manipulating files Python 2.7 - by hugobaur - Oct-21-2016, 01:20 PM
RE: Manipulating files Pytohn 2.7 - by Ofnuts - Oct-21-2016, 04:53 PM
RE: Manipulating files Pytohn 2.7 - by hugobaur - Oct-25-2016, 11:53 AM
RE: Manipulating files Python 2.7 - by Ofnuts - Oct-25-2016, 01:02 PM
RE: Manipulating files Python 2.7 - by hugobaur - Oct-31-2016, 06:37 PM
RE: Manipulating files Python 2.7 - by snippsat - Oct-31-2016, 07:16 PM
RE: Manipulating files Python 2.7 - by hugobaur - Nov-01-2016, 12:28 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Manipulating data from a CSV EvanS1 5 2,809 Jun-12-2020, 05:59 PM
Last Post: perfringo
  manipulating two lists rancans 8 3,345 Apr-16-2020, 06:00 PM
Last Post: deanhystad
  Manipulating index value, what is wrong with this code? Emun 1 1,849 Feb-05-2020, 07:18 AM
Last Post: perfringo
  Manipulating the filename of an output script mckinneycm 4 12,016 Jan-15-2020, 07:29 PM
Last Post: mckinneycm
  Manipulating Excel with Python. Spacely 2 3,761 Jun-25-2019, 01:57 AM
Last Post: Dequanharrison
  Manipulating CSV Prince_Bhatia 1 2,003 Apr-25-2019, 11:55 AM
Last Post: Gribouillis
  Reading and manipulating csv Prince_Bhatia 11 5,249 Mar-14-2019, 11:40 AM
Last Post: Larz60+
  Manipulating an Excel Workbook Stanimal 4 3,076 Jan-18-2019, 11:03 PM
Last Post: Stanimal
  Running a python tool transforming xml files into epub files silfer 7 5,594 May-10-2018, 03:49 PM
Last Post: snippsat
  Manipulating Binary Data arsenal88 10 8,848 Apr-25-2017, 02:30 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020