반응형

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)
반응형

'Python' 카테고리의 다른 글

파이썬 lambda 사용시  (0) 2023.06.01
print 하면 <map object at 0x10446d880> 나올 때  (0) 2023.06.01
[python] list 사용 방법  (0) 2023.05.29
zip()  (0) 2023.05.03
combinations()  (0) 2023.05.03

+ Recent posts