detect_encoding method
Leave feedback
On this page
Detects the encoding of text TXT, TSV, and CSV files by path.
def detect_encoding(cls, file_path):
...
| Parameter | Type | Description |
|---|---|---|
| file_path | str |
The file name or file path. |
Returns: str or None: The detected encoding name, or None when detection fails.
from groupdocs.viewer import FileType
encoding = FileType.detect_encoding("message.txt")
if encoding:
print(f"Detected encoding: {encoding}")
else:
print("Failed to detect encoding.")
Attempts to detect the encoding of text files (TXT, TSV, CSV) from a stream.
def detect_encoding(cls, stream):
...
| Parameter | Type | Description |
|---|---|---|
| stream | io.RawIOBase |
The file stream. |
Returns: Encoding or None: The detected encoding, or None if detection fails.
from groupdocs.viewer import FileType
with open("message.txt", "rb") as stream:
encoding = FileType.detect_encoding(stream)
print(encoding)
- class
FileType
Was this page helpful?
Any additional feedback you'd like to share with us?
Please tell us how we can improve this page.
Thank you for your feedback!
We value your opinion. Your feedback will help us improve our documentation.