Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to overwrite file
#4
I had the same problem with my Sync-It app this week.
I used "W+" for all the writes and to clear the log, and setting up the log.

I used this to clear the log:
with open('syncit.log', 'w+'):
    pass
I did this on start up and after the log details had been displayed
and I didn't need the data any more.

Then I had the problem that clearing it this way (on my Windows computer at least)
it left a lot of "NUL" characters that confused my code when I tried
to read the lines into strings.

To remove these I found a re solution on stackoverflow:

line = re.sub(r'[\x00-\x1F]+', '', line) # Strip some non ASCII.
and all my problems were solved.

See my GitHub repositories for Sync-It code if you want.
https://github.com/steveshambles?tab=repositories
I'm working on an update at the moment V0.37 with much improved code and a few new features
should be uploading it to GitHub tomorrow sometime.
Reply


Messages In This Thread
How to overwrite file - by SriRajesh - Apr-12-2020, 11:29 AM
RE: How to overwrite file - by deanhystad - Apr-13-2020, 08:06 PM
RE: How to overwrite file - by SriRajesh - Apr-14-2020, 12:17 AM
RE: How to overwrite file - by steve_shambles - Apr-14-2020, 12:57 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Openpyxl overwrite Linechart SamLiu 0 869 Nov-26-2022, 05:44 AM
Last Post: SamLiu
  Overwrite values in XML file with values from another XML file Paqqno 5 3,296 Apr-01-2022, 11:33 PM
Last Post: Larz60+
  Overwrite previous live data. Makada 2 2,352 Nov-07-2020, 07:40 PM
Last Post: Makada
  Dict overwrite previous list vincentspm 1 2,215 Mar-20-2019, 12:31 PM
Last Post: scidam
  overwrite data using openpyxl BNB 0 10,570 Jun-21-2017, 11:31 AM
Last Post: BNB

Forum Jump:

User Panel Messages

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