Код: Выделить всё
[(3479865,
PaginatedManagedEntityHeaders(
success=True,
count=0,
rows=[
ManagedEntityHeader(
case_role='Reference',
display_name='Person A',
entity_type='PERSON',
unique_id=247878382,
is_active='1',
date_created=datetime.datetime(2021, 10, 18, 16, 29, 6, 535000, tzinfo=TzInfo(UTC))),
ManagedEntityHeader(
case_role='Reference',
display_name='Person B',
entity_type='PERSON',
unique_id=247563788,
is_active='0',
date_created=datetime.datetime(2021, 9, 8, 21, 4, 29, 631000, tzinfo=TzInfo(UTC)))]
))]
Код: Выделить всё
import os
import json
import ast
import re
the_file = os.path.join(r"test_fixture.json")
file_str = open(the_file).read()
meth1 = file_str.strip("][").split(", ")
# receive a list of 25 instead of a list of 1
meth2 = ast.literal_eval(file_str)
# ValueError: malformed node or string on line 2:
meth3 = json.loads(file_str)
# JSONDecodeError: Expecting value
elements = re.findall(r"\d+", file_str)
meth4 = [int(x) for x in elements]
# receive a list of 20 instead of a list of 1
meth5 = eval(file_str)
# NameError: name 'PaginatedManagedEntityHeaders' is not defined
meth6 = list(map(int, file_str[1:-1].split(",")))
# ValueError: invalid literal for int() with base 10: '(3479865'
Код: Выделить всё
meth_that_worked
Код: Выделить всё
print(meth_that_worked)
Код: Выделить всё
print(type(meth_that_worked))
Подробнее здесь: https://stackoverflow.com/questions/786 ... which-look