Python gets file encoding (including HTML TXT Doc, etc.)
import chardet
def get_file_encoding(file_path):
f3 = open(file_path, mode='rb') # Read files in binary mode
data = f3.read() # Get file contents
f3.close() # Close the file.
result = chardet.detect(data) # Detect file contents
return result.get("encoding")
Read More:
- Python: How to parses HTML, extracts data, and generates word documents
- Python: How to handles HTML escape characters
- How to Fix Python reading large local file memory error
- How to Solve Python WARNING: Ignoring invalid distribution -ip (e:\python\python_dowmload\lib\site-packages)
- Python openpyxl excel open zipfile error resolution: zipfile.BadZipFile: File is not a zip file
- python: File Processing and Input and Output
- [CHM] Python: How to Extract CHM Data
- Invalid python sd, Fatal Python error: init_fs_encoding: failed to get the Python cod [How to Solve]
- Python: How to Auto Add Watermark to PDF
- [Solved] Python Read bam File Error: &&OSError: no BGZF EOF marker; file may be truncated
- Pychar can’t connect to Python console, but it can run. Py file, and Anaconda’s command line can run Python command
- How to Solve Python Pandas Read or Import Files Error
- Python: How to Delete Empty Files or Folders in the Directory
- Python: How to Solve error While importing windpy
- Python: How to Create an Automatic Recording Program
- How to Fix Errors encountered in executing Python scripts with command line parameters
- Python: How to Use os.path.join()
- Python: How to Disable InsecureRequestWarning error
- Python: How to Obtaining Publick IP Quickly
- Python: How to get the size of the picture (byte/kb/mb)