In Python, when we are working with files that contain a large amount of data then it is often inefficient to read the entire content into memory at once. In such cases, we can read a fixed amount of data at a time by using the read() method with a specified size. This process is commonly known as buffered or chunk-based reading. The Chunk-based reading is a program to read a file piece-by-piece rather than loading it completely. This process is particularly helpful when handling large files, as it helps to reduce memory consumption and enhances performance during file processing operations. ... Read More
The given task is to list the directory tree structure, i.e., we need to print the hierarchy of folders and files starting from a specified root directory. This is similar to how the tree command works in Linux or Windows by showing nested folders and files in a structured and indented format. In this article, we will see all the possible methods in Python to list the directory tree structure. Using os.walk() Method The os.walk() method in Python is used to generate the file names and folder names in a directory tree by parsing through the tree in either a ... Read More
Python uses indentation to define blocks of code instead of curly braces or keywords. If the indentation is not correct, Python raises an IndentationError. In this article, you will learn how to catch and handle IndentationError in Python using various approaches. An IndentationError in Python occurs when the indentation rules are not followed properly. It is raised during the parsing stage, not during execution. Therefore, to catch it, you must execute the code dynamically as a string. Using exec(), compile(), and custom wrapper functions, you can catch and handle this error in Python programs. We can use the following methods ... Read More
A TypeError occurs in Python when we perform an operation on an object of an inappropriate type. For example, adding a string to an integer or calling a non-callable object. In this article, you will learn how to catch and handle TypeError exceptions using different methods in Python. TypeError is raised when you use the wrong data type in an operation. You can handle this exception using try-except blocks to prevent the program from crashing and help you correct input. Always test your code where type mismatches are possible, especially when working with user input or dynamic data. There are ... Read More
In Python, the EnvironmentError occurs when errors related to the system's environment, such as file I/O issues or hardware failures, occur. In the latest Python versions (i.e., 3.3+), this exception is the same as OSError. In this article, you will learn how to catch EnvironmentError (or OSError) to handle system-level errors and prevent programs from crashing abruptly. Some of the common reasons to catch EnvironmentError are - When a file operation fails When a directory cannot be accessed or found When a hardware or device-related issue occurs Using try-except to Catch EnvironmentError To catch EnvironmentError, use a try-except ... Read More
The size of a pointer in C/C++ is not fixed. It depends upon different issues like Operating system, CPU architecture etc. Usually it depends upon the word size of underlying processor, for example for a 32 bit computer the pointer size can be 4 bytes and for a 64 bit computer the pointer size can be 8 bytes. So for a specific architecture pointer size will be fixed. It is common to all data types like int *, float * etc. Depending on the system architecture, pointer size may vary. The following table shows the pointer size based on the ... Read More
An array is a collection of elements of the same type such as integers, string, etc. Array in STL In C++ Standard Template Library (STL) , we use std::array container to create arrays with a fixed size. the size cannot be changed once created. It works like a normal array but with extra features like knowing its own size and working with STL functions. Syntax Following is the syntax to create an array in C++ STL: array(data_type, size) array_name = {va1, val2, ...valn}; Here, data_type: It specifies the type of data array will accept. it can be any ... Read More
A circular singly linked list is a type of data structure that is made up of nodes that are created using self-referential structures. Each node contains two components, namely the data element and the reference to the next node in the list. Only the reference to the head node is required to access the whole linked list. The last node of the list points to the head node, which makes it a circular linked list. Let's see a diagram of circular linked list. Circular linked lists are mainly useful for scheduling tasks and managing playlists, enabling smooth navigation. ... Read More
A pure virtual function is a function that has no implementation in the base class and must be overridden by any derived class. It is declared using = 0 in the base class. Pure Virtual Destructor When we want the base class to be abstract then we declare a pure virtual Destructor. A pure virtual Destructor can be declared in C++ after a destructor has been created as a pure virtual object. One of the most important things is that if a class contains a pure virtual destructor, it must provide a function body for the pure virtual destructor. ... Read More
A fusion tree is a tree data structure that implements an associative array on w-bit integers. Here, W is the number of bits in the integer. A fusion tree is used to maintain the ordered set of elements. It uses a combination of a B-tree and a hash table that helps reduce the time complexity of the operations like insertion, deletion, and searching in the tree. How Fusion Tree Works? The following are the factors that should be considered while implementing the fusion tree: Bit manipulation: The tree extracts specific bits from stored integers and ... Read More