Python Forum
Failure in writing binary text to file
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Failure in writing binary text to file
#2
If you encode an ascii string with the UTF-8 encoding, it does not change a single byte. For non ascii characters there are more bytes.
>>> "Hello InfinityQuest!".encode('utf-8')
b'Hello InfinityQuest!'
>>> "hétérogénéité".encode('utf-8')
b'h\xc3\xa9t\xc3\xa9rog\xc3\xa9n\xc3\xa9it\xc3\xa9'
Your way to write binary files is perfect.
Reply


Messages In This Thread
Failure in writing binary text to file - by Gigux - Jul-02-2020, 08:31 PM
RE: Failure in writing binary text to file - by Gribouillis - Jul-02-2020, 09:09 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Failure to run source command middlestudent 2 760 Sep-22-2023, 01:21 PM
Last Post: buran
  How do I read and write a binary file in Python? blackears 6 7,412 Jun-06-2023, 06:37 PM
Last Post: rajeshgk
Thumbs Up Need to compare the Excel file name with a directory text file. veeran1991 1 1,175 Dec-15-2022, 04:32 PM
Last Post: Larz60+
  Script File Failure-Path Error? jerryf 13 3,597 Nov-30-2022, 09:58 AM
Last Post: jerryf
  Writing string to file results in one character per line RB76SFJPsJJDu3bMnwYM 4 1,457 Sep-27-2022, 01:38 PM
Last Post: buran
  Dickey Fuller failure Led_Zeppelin 4 2,709 Sep-15-2022, 09:07 PM
Last Post: Led_Zeppelin
  Writing into 2 text files from the same function paul18fr 4 1,753 Jul-28-2022, 04:34 AM
Last Post: ndc85430
  Writing to json file ebolisa 1 1,057 Jul-17-2022, 04:51 PM
Last Post: deanhystad
  Modify values in XML file by data from text file (without parsing) Paqqno 2 1,765 Apr-13-2022, 06:02 AM
Last Post: Paqqno
  Writing to External File DaveG 9 2,602 Mar-30-2022, 06:25 AM
Last Post: bowlofred

Forum Jump:

User Panel Messages

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