mirror of
https://github.com/hwchase17/langchain
synced 2024-11-10 01:10:59 +00:00
18 lines
527 B
Python
18 lines
527 B
Python
|
import tokenize
|
||
|
|
||
|
from langchain_community.document_loaders.text import TextLoader
|
||
|
|
||
|
|
||
|
class PythonLoader(TextLoader):
|
||
|
"""Load `Python` files, respecting any non-default encoding if specified."""
|
||
|
|
||
|
def __init__(self, file_path: str):
|
||
|
"""Initialize with a file path.
|
||
|
|
||
|
Args:
|
||
|
file_path: The path to the file to load.
|
||
|
"""
|
||
|
with open(file_path, "rb") as f:
|
||
|
encoding, _ = tokenize.detect_encoding(f.readline)
|
||
|
super().__init__(file_path=file_path, encoding=encoding)
|