<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="3.9.0">Jekyll</generator><link href="https://negator92.github.io/feed.xml" rel="self" type="application/atom+xml" /><link href="https://negator92.github.io/" rel="alternate" type="text/html" /><updated>2021-03-05T06:34:18+00:00</updated><id>https://negator92.github.io/feed.xml</id><title type="html">Vincent Neparidze</title><subtitle>C# developer from Moscow, Russia</subtitle><entry><title type="html">Python dynamic deserialize</title><link href="https://negator92.github.io/Python-dynamic-deserialize/" rel="alternate" type="text/html" title="Python dynamic deserialize" /><published>2021-03-05T00:00:00+00:00</published><updated>2021-03-05T00:00:00+00:00</updated><id>https://negator92.github.io/Python-dynamic-deserialize</id><content type="html" xml:base="https://negator92.github.io/Python-dynamic-deserialize/">&lt;p&gt;First of all, I must warn you: the explicit is better than the implicit.&lt;/p&gt;

&lt;p&gt;Since I needed to deserialize a certain amount of data from a json file, I ran into the problem that today I have 3 key-value pairs, tomorrow there are 5, and by the end of the month there may be 11 of them.
I didn’t want to describe so many fields in the class constructor, and since my json file contains only settings, usernames, passwords, and tokens (I will definitely hash them instead of storing them in an open strings), I know what to expect to get from the file.&lt;/p&gt;

&lt;p&gt;I used the following construction for such a codehack to get the desired result:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;import json

class ClassName(object):
    def __init__(self, j):
        self.__dict__ = json.loads(j)

with open('Configuration.json', 'r', encoding='utf-8') as configFile:
    jsonStr = configFile.read()

config = Configuration(jsonStr)

print(config.username)
print(config.password)
print(config.token)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;This allowed me to avoid writing scary references to the dictionary element.
Nevertheless, I must repeat that the explicit is better than the implicit. The fact that I have to write in a dynamic language relaxes me too much and makes me lazy, although I understand that in C# I would describe every field, perhaps I would also use attributes (but this is not accurate, lol).&lt;/p&gt;</content><author><name></name></author><summary type="html">First of all, I must warn you: the explicit is better than the implicit.</summary></entry><entry><title type="html">First post!</title><link href="https://negator92.github.io/Hello-World/" rel="alternate" type="text/html" title="First post!" /><published>2021-02-17T00:00:00+00:00</published><updated>2021-02-17T00:00:00+00:00</updated><id>https://negator92.github.io/Hello-World</id><content type="html" xml:base="https://negator92.github.io/Hello-World/">&lt;p&gt;Hello there!
It’s first post on my blog.&lt;/p&gt;</content><author><name></name></author><summary type="html">Hello there! It’s first post on my blog.</summary></entry></feed>