How can I write a one character file in Python 3.8 that has the text/plain mime type?
Using Python, if I write one character to a file, the mime type of the file is application/octet-stream.
with open('file_from_python', 'w') as f: f.write('x')
(Note: Writing more than one character using the Python code above results in the text/plain mime type; the issue only occurs when you write less than two characters to a file).
Check the mime type of the python generated file using the following Linux command line:
file --mime-type file_from_python
file_from_python: application/octet-stream
Using the Linux terminal, if I write one character to a file, the mime type of the file is text/plain.
echo "x" > file_from_bash
Check the mime type of the Linux terminal generated file using the following Linux command line:
file --mime-type file_from_bash
file_from_bash: text/plain