I tried to write the following code and write the data to the file, but I got the following error...
How can I modify the code below to write text data to a file simply...? I would appreciate it if you could let me know.(By the way, my python was python2...)
Code
with open(text_file, 'w', encoding="utf-8") asfp:#Where the error occurs
fp.write(text)
Error
Traceback (most recent call last):
File "ExtractText.py", line 36, in <module>
with open(text_file, 'w', encoding="utf-8") asfp:
TypeError: 'encoding' is an invalid keyword argument for this function
By the way, if you erase the encoding argument, you get the following error...
Code
with open(text_file, 'w') asfp:# Where the error occurs
fp.write(text)
Error
Traceback (most recent call last):
File "ExtractText.py", line 37, in <module>
fp.write(text)
UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-10:ordinal not in range (128)
When writing, not when reading.
fp.write(text)
You may be experiencing an error in .
for.write(text.encode("utf-8")))
Can't you?
I wonder if the encoding of the platform is different.
If you try encoding="shift_jis", you may be able to do it
911 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
578 Understanding How to Configure Google API Key
574 Who developed the "avformat-59.dll" that comes with FFmpeg?
581 PHP ssh2_scp_send fails to send files as intended
572 rails db:create error: Could not find mysql2-0.5.4 in any of the sources
© 2024 OneMinuteCode. All rights reserved.