Python

File 읽어서 객체에 담기

RailCoder 2024. 9. 4. 12:47
반응형

File 읽어서 객체에 담기

# test 객체


class test:
	name: str
    age: int

def test():
    file_path = "test.txt"
    # 파일 읽기
    with open(file_path, 'r', encoding='UTF8') as file:
        file_content = file.read()

    # JSON 파싱
    data = json.loads(file_content)
    x = data["data"]

    # Syncer 인스턴스 생성
    test_data = test(**x)
반응형