Solidity Ether Units, Time Units, and Global Variables

With this article, we’re opening a new area of our study, that of units and globally available variables in Solidity. To begin with, we’ll learn about ether units and time units. After that, we’ll start with a block of subsections on special variables and functions, stretching through this and the next two articles. It’s part … Read more

Solidity Conversions of Elementary Types

In this article, we’ll entertain ourselves with conversions between elementary types in Solidity. We’ll mention implicit and explicit conversions, as well as conversions between literals. It’s part of our long-standing tradition to make this (and other) articles a faithful companion, or a supplement to the official Solidity documentation, for this article’s topic. Implicit Conversions The … Read more

Python – Hex String to Bytearray

Problem Formulation Given a string in hexadecimal form: How to convert the hex string to a bytearray object in Python? Here are a few examples: Hex String Bytearray Object ’01’ bytearray(b’\x01′) ’04’ bytearray(b’\x04′) ’08’ bytearray(b’\x08′) ’01 0a’ bytearray(b’\x01\n’) ’01 02 0e 0f 0f’ bytearray(b’\x01\x02\x0e\x0f\x0f’) ‘0f 0f’ bytearray(b’\x0f\x0f’) Hex String to Bytearray using bytearray.fromhex(hex_string) To convert … Read more

Parsing XML Files in Python – 4 Simple Ways

Problem Formulation and Solution Overview This article will show you various ways to work with an XML file. ℹ️ XML is an acronym for Extensible Markup Language. This file type is similar to HTML. However, XML does not have pre-defined tags like HTML. Instead, a coder can define their own tags to meet specific requirements. … Read more

How to Schedule a Batch Python Script

Problem Formulation and Solution Overview During your career as a Pythonista, you will encounter situations where a Python script will need to be executed on a scheduled basis, such as daily, weekly, or monthly. This article shows you how to accomplish this task using a .bat (batch) file. πŸ’¬ Question: How would we write code … Read more

Python | Split String by Multiple Characters/Delimiters

Summary: The most efficient way to split a string using multiple characters is to use Python’s regex library as re.split(“pattern”, “given_string”). An alternate solution is to replace the delimiters in the given string with a whitespace character and then split the string. Minimal Example: Problem Formulation πŸ“œProblem: Given a string. How will you split the … Read more

Python | Split String and Keep Newline

Summary: Use ‘given_string’.splitlines(True) to split the string and also keep the new line character. Minimal Example: Problem Formulation πŸ“œProblem: Given a string. How will you split the string into a list of substrings and keep the new line character intact? Example: Let’s have a look at a test case to understand the given problem. Without … Read more

Python getattr() and setattr() Nested

Understanding Python’s setattr() and getattr() Functions Next, you’ll learn about the “normal”, non-nested and non-recursive get and set attribute functions. If you already know them well, there’s no need to read this section and you can skip ahead right to the problem formulation and solution. Let’s start with the setattr() function, followed by getattr(). setattr() … Read more