(Solved) Python TypeError ‘Method’ Object is Not Subscriptable

The β€œTypeError: ‘method’ object is not subscriptable” occurs when you call a method using square brackets, e.g., object.method[3]. To fix it, call the non-subscriptable method only with parentheses like so: object.method(3). How Does the Error Occur (Example) In the following minimal example, you attempt to define a custom “list” class and you try to access … Read more

How to Sum the Digits of a Number in Python?

Problem Formulation Given an integer number. How to sum over all digits of this number to compute the crossfoot (cross total)? Consider the following examples: 12 –> 1+2 = 3 123 –> 1+2+3 = 3 244 –> 2+4+4 = 10 981223 –> 9+8+1+2+2+3 = 25 Method 1: sum() with Generator Expression The Python built-in sum(iterable) … Read more

Python Time Series Forecast on Bitcoin Data (Part II)

A Time Series is essentially a tabular data with the special feature of having a time index. The common forecast taks is ‘knowing the past (and sometimes the present), predict the future’. This task, taken as a principle, reveals itself in several ways: in how to interpret your problem, in feature engineering and in which … Read more

How to Subtract Two Python Lists (Element-Wise)?

Problem Formulation and Solution Overview This article will show you how to subtract two Lists in Python. πŸ’‘ Note: Before subtracting these Lists, ensure each List is of the same length and contains subtractable data. For example, subtracting a List of strings from a List of integers or floats will result in an error. Whereas … Read more

How to Concatenate a Boolean to a String in Python?

Easy Solution Use the addition + operator and the built-in str() function to concatenate a boolean to a string in Python. For example, the expression ‘Be ‘ + str(True) yields ‘Be True’. The built-in str(boolean) function call converts the boolean to a string. The string concatenation + operator creates a new string by appending the … Read more

(Fixed) Python TypeError ‘bool’ object is not subscriptable

Problem Formulation Consider the following minimal example where a TypeError: ‘bool’ object is not subscriptable occurs: This yields the following output: Solution Overview Python raises the TypeError: ‘bool’ object is not subscriptable if you use indexing or slicing with the square bracket notation on a Boolean variable. However, the Boolean type is not indexable and … Read more

Python Scrapy – Scraping Dynamic Website with API-Generated Content

Scrapy is an excellent tool for extracting data from static and dynamic websites. In this article, we are going to discuss the solution to the following problems: Extract all details of Offices from the website https:/directory.ntschools.net/#/offices Instead of using a whole scrapy framework, use a typical Python script for extracting the data. For each office, … Read more

How to Determine Script Execution Time in Python?

Problem Formulation and Solution Overview This article will show you how Python can determine a script’s execution time. Let’s say you have written several code sections. Each section performs identical tasks. How could you best determine which section works faster and more efficiently? πŸ’¬ Question: How would we write code to determine a script’s execution … Read more

Solidity Fixed Point Numbers and Address Types (Howto)

With this article, we continue our journey through the realm of Solidity data types. πŸ‘‰ Recommended Tutorial: Solidity Basic Data Types This time, we will focus on fixed point numbers, address types and address type members, and investigate when, how, and why they are used. Traditionally, our articles are running alongside the official Solidity documentation … Read more

How to Update Python?

Python gets updated roughly once per year with a major update and security fixes. So, Python’s update cycle is 12 months. The end-of-life, i.e., the period during which one Python version is supported, is normally set to 5 years. The following graphic shows a great screenshot of supported and unsupported Python versions at the time … Read more