Niharikaa Aitam

Niharikaa Aitam

77 Articles Published

Articles by Niharikaa Aitam

Page 4 of 8

How to extract all the .txt files from a zip file using Python?

Niharikaa Aitam
Niharikaa Aitam
Updated on 24-Mar-2026 3K+ Views

Python provides a built-in module called zipfile that allows us to create, read, write, and extract ZIP archives. When we want to extract only specific files, such as all .txt files, we can filter file names using string methods like endswith() or the pathlib module. A ZIP file is an archive format used to compress one or more files into a single file for easy storage and transfer. It reduces file size and keeps related files together for sharing over the internet and saving disk space. Steps for Extracting Specific Files Follow these steps to ...

Read More

How are files extracted from a tar file using Python?

Niharikaa Aitam
Niharikaa Aitam
Updated on 24-Mar-2026 22K+ Views

A TAR file is abbreviated as Tape Archive, which is an archive format used mainly in Unix and Linux environments. The Tar file is used to collect multiple files into a single file, which makes it easier to share or backup together. In Python, when we want to work with TAR files, we can use the tarfile module, which allows us to create, read and extract TAR archives programmatically. In this article, we will explore how to extract files from a tar file using Python. Extracting All Files from a Tar File The extractall() method in ...

Read More

How are files added to a tar file using Python?

Niharikaa Aitam
Niharikaa Aitam
Updated on 24-Mar-2026 3K+ Views

Python offers a built-in module named tarfile, which allows developers to create, read, and modify tar archives (standard Unix tarballs). We can use this module to compress multiple files into a single archive, with or without compression. File Modes for Creating Tar Archives Here are the available file modes to create a tar file using Python − "w": Write a tar archive without compression. "w:gz": Write a gzip-compressed archive. "w:bz2": Write a bzip2-compressed archive. "w:xz": Write an xz-compressed archive (Python 3.3+). Adding a Single File to ...

Read More

How an entire file is read into buffer and returned as a string in Python?

Niharikaa Aitam
Niharikaa Aitam
Updated on 24-Mar-2026 9K+ Views

When dealing with files in Python, we can read the entire file into memory as a string or process it in chunks using a buffer. This article explores different approaches to read files efficiently, including reading the entire content at once and using buffered reading for large files. Syntax The basic syntax for reading a file with a specified buffer size is ? with open('filename', 'r') as file: chunk = file.read(buffer_size) Where: filename: The path of the file 'r': Read ...

Read More

What is the maximum size of list in Python?

Niharikaa Aitam
Niharikaa Aitam
Updated on 24-Mar-2026 6K+ Views

In Python, a list is a dynamic array that can be expanded in size as needed. The maximum size of a list is limited by the system's memory and the platform's architecture. In this article, we will explore how to determine the maximum size of a list in Python. Understanding Python List Limits The size of a list in Python is not restricted by any fixed value set in the language itself. Instead, it depends on several factors ? Available system memory (RAM) System architecture (32-bit or 64-bit) The value of sys.maxsize Maximum Size ...

Read More

What is the maximum length of string in Python?

Niharikaa Aitam
Niharikaa Aitam
Updated on 24-Mar-2026 8K+ Views

In Python, strings are dynamic and can grow to very large sizes, limited only by the system's available memory. Unlike some other languages, Python does not define a strict upper bound on string length. The practical maximum length of a string depends on the platform and memory constraints. In this article, we will explore how to determine the theoretical maximum string length in Python and understand the practical limitations. Maximum Theoretical String Length Python strings are stored as sequences of Unicode characters, and the maximum size of a Python object is typically constrained by the value of ...

Read More

What is the maximum value of float in Python?

Niharikaa Aitam
Niharikaa Aitam
Updated on 24-Mar-2026 1K+ Views

In Python, floating-point numbers are implemented using double-precision, i.e., 64-bit format, as per the IEEE 754 standard. These floats have a finite range and precision. The maximum value that a float can represent depends on the platform, but can be accessed using the sys.float_info attribute. Maximum Value of Float using sys.float_info The sys.float_info object provides details about the float implementation on the current platform. The attribute float_info.max gives the largest positive floating-point number representation. Example Here we use float_info.max attribute from the sys.float_info object to get the maximum float value in Python − ...

Read More

How to sort a dictionary in Python by values?

Niharikaa Aitam
Niharikaa Aitam
Updated on 24-Mar-2026 2K+ Views

Python allows dictionaries to be sorted using the built-in sorted() function. In this article, we will explore different ways to sort a dictionary in Python by its values. Using itemgetter() Method The itemgetter() method from the operator module provides an efficient way to sort dictionaries by values. It returns a callable object that fetches an item from its operand using the provided index ? from operator import itemgetter dictionary = { 'b': 2, 'a': 1, 'd': 4, 'c': 3 ...

Read More

How to sort a dictionary in Python by keys?

Niharikaa Aitam
Niharikaa Aitam
Updated on 24-Mar-2026 770 Views

Python allows dictionaries to be sorted using the built-in sorted() function. Although dictionaries in Python 3.7+ preserve insertion order, we can still create a new dictionary sorted by its keys using various methods. In this article, we will explore different ways to sort a dictionary in Python by its keys. Using sorted() with Dictionary Comprehension The most Pythonic way to sort a dictionary by keys is using dictionary comprehension with the sorted() function. This creates a new dictionary with keys in alphabetical order − data = { 'zebra': 26, ...

Read More

How do we specify the buffer size when opening a file in Python?

Niharikaa Aitam
Niharikaa Aitam
Updated on 24-Mar-2026 10K+ Views

When opening a file using Python's built-in open() function, the data temporarily stored in memory can be managed by setting the buffering parameter. Buffering helps improve file I/O performance by reducing the number of disk interactions during read/write operations. Understanding the Buffering Parameter The buffering parameter in Python's open() function allows us to define how much data is stored in memory before being written to or read from the file. This parameter is essential when handling large files or frequent write operations ? Syntax open(file, mode='r', buffering=-1, encoding=None, ...) Buffering Modes The ...

Read More
Showing 31–40 of 77 articles
« Prev 1 2 3 4 5 6 8 Next »
Advertisements