adds similar functionality in python…

This commit is contained in:
2024-04-21 00:28:13 +02:00
parent 1939cd990e
commit 76d2662a2f

38
python_src/try_out.py Normal file
View File

@@ -0,0 +1,38 @@
import json
class Address:
def __init__(self, street, number, city):
self.street = street
self.number = number
self.city = city
class Person:
def __init__(self, name, age, email, address, hobbies, friends):
self.name = name
self.age = age
self.email = email
self.address = address
self.hobbies = hobbies
self.friends = friends
def __str__(self):
return self.name + ', ' + str(self.age) + ', ' + self.email
file = open('../JSON/alice.json')
json_person = json.load(file)
file.close()
json_address = json_person['address']
python_address = Address(json_address['street'], json_address['number'], json_address['city'])
python_person = Person(json_person['name'],
json_person['age'],
json_person['email'],
python_address,
json_person['hobbies'],
json_person['friends'])
print(python_person)
print('Friends with: ')
for friend in python_person.friends:
print(friend)