-
Notifications
You must be signed in to change notification settings - Fork 0
/
rowDataFromFile.py
38 lines (30 loc) · 1.31 KB
/
rowDataFromFile.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
from os.path import expanduser, join
import pandas
import json
import requests
class RowDataFromFile:
# хранит в себе данные из JSON в формате DataFrame
# Initializer выполняется перед! основной программой.
# Private Instance or static Class attribute. Переменные должны начинаться с двух подчеркиваний.
__fileName: str = "/home/dimitri/Загрузки/601285.json"
__data: dict = None
# Constructors
def __init__(self, file_name: str = "/home/dimitri/Загрузки/601285.json") -> None:
self.__fileName = file_name
# Opening JSON file
f = open(self.__fileName)
# returns JSON object as
# a dictionary
self.__data = json.load(f)
# Closing file
f.close()
# Methods
# Accessor( = getter) methods
def get_json(self) -> dict:
print(f"JSON fetched from file {self.__fileName}")
return self.__data
if __name__ == '__main__':
fileName: str = join(expanduser("~"), "Downloads", "601285.json")
rowData: RowDataFromFile = RowDataFromFile(file_name=fileName) # object must start from lower-case letter
dictOut: pandas.DataFrame = rowData.get_json()
pass # Press Ctrl+8 to toggle the breakpoint.