A data analyst built a blockchain in Python
As a data analyst, we’ve used Pandas so often that we take Python for granted as an object-oriented programming language. For example, we care about data types like numeric, string, object, etc. But, for Python programming, you need to create objects by defining a class and assigning values to the class. Conceptually, it’s not the hardest thing in the world, but we rarely make our objects in data analysis an alien concept – at least to me anyway.
- Objects in Python are data variables and methods that act on data as a single entity.
- Class means the plane of the object; or how the object is constructed.
- _init_ is the constructor of the object. that is to say. you instantiate or realize the object.
- self means you want the value to persist in the object.
- haslib.sha256 is an encryption algorithm.
- hexdigest returns encoded data in hexadecimal format, or something more readable.
At least according to the tutorials, it looks like we need to create classes for our blockchain. Nevertheless, the blockchain class is easy to translate. It just says to add a new encrypted block each time a transaction on the block occurs.
Due to my poor basic Python and web development skills, I originally found the tutorials quite challenging. I’m really surprised how unprepared learning Python for data analysis makes you for other programming tasks. The moral of the story for me is – aim to be a well-rounded Python developer with data science skills from the start.