Python Forum
What is meant by "truncates the file" RE file.open(w+b)?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
What is meant by "truncates the file" RE file.open(w+b)?
#3
The "wb truncates" means that opening a file with "w" (the "b" doesn't matter for this) resets the file to empty. Truncates is not a great choice of words because we are used to "truncate to a value" or "truncate to a precision". Here it means "truncate to 0 bytes".

There is only one place you should ever write to a file, after the end. You can do this with an empty file, or with a file that contains values. You need to be really careful when trying to write anywhere else.
Reply


Messages In This Thread
RE: What is meant by "truncates the file" RE file.open(w+b)? - by deanhystad - Sep-01-2020, 03:14 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Open/save file on Android frohr 0 417 Jan-24-2024, 06:28 PM
Last Post: frohr
  file open "file not found error" shanoger 8 1,417 Dec-14-2023, 08:03 AM
Last Post: shanoger
  Need to replace a string with a file (HTML file) tester_V 1 856 Aug-30-2023, 03:42 AM
Last Post: Larz60+
  How can i combine these two functions so i only open the file once? cubangt 4 991 Aug-14-2023, 05:04 PM
Last Post: snippsat
  How can I change the uuid name of a file to his original file? MaddoxMB 2 1,065 Jul-17-2023, 10:15 PM
Last Post: Pedroski55
  Reading data from excel file –> process it >>then write to another excel output file Jennifer_Jone 0 1,220 Mar-14-2023, 07:59 PM
Last Post: Jennifer_Jone
  I cannot able open a file in python ? ted 5 3,838 Feb-11-2023, 02:38 AM
Last Post: ted
  testing an open file Skaperen 7 1,527 Dec-20-2022, 02:19 AM
Last Post: Skaperen
Thumbs Up Need to compare the Excel file name with a directory text file. veeran1991 1 1,217 Dec-15-2022, 04:32 PM
Last Post: Larz60+
Photo Making Zip file of a file and Directory Nasir 2 1,097 Oct-07-2022, 02:01 PM
Last Post: Nasir

Forum Jump:

User Panel Messages

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