Sarika Singh has Published 118 Articles

How to print all the keys of a dictionary in Python

Sarika Singh

Sarika Singh

Updated on 16-May-2025 10:46:37

107K+ Views

A Python dictionary is an unordered collection of data values. It contains a key-value pair, in contrast to other data structures that only include one value per entry. In this article, we are going to see the various ways to print all the keys of a dictionary in Python. Using dict.keys() ... Read More

What does the 'b' modifier do when a file is opened using Python?

Sarika Singh

Sarika Singh

Updated on 15-May-2025 18:23:46

13K+ Views

When we use the b modifier while opening a file, then the file is opened in binary mode. Any file whose format doesn't consist of readable characters is referred to as a "binary" file. Binary files include audio files like MP3s, text formats such as Word or PDF, and image files ... Read More

How to check file last access time using Python?

Sarika Singh

Sarika Singh

Updated on 15-May-2025 18:23:11

3K+ Views

Monitoring file access times is a common requirement for auditing, data management and cleanup of the scripts. Python provides multiple ways to retrieve the last access time of a file using the os and pathlib modules. Using os.path.getatime() Method In Python, we can use the os.path.getatime() method to retrieve a ... Read More

How to find the real user home directory using Python?

Sarika Singh

Sarika Singh

Updated on 15-May-2025 18:21:27

16K+ Views

When working with the Python scripts, it is required to interact with user-specific files or directories and also it's essential to accurately determine the actual user's home directory. This is especially important if the script might be executed with elevated privileges like using sudo where default methods could mistakenly point ... Read More

How to move a file from one folder to another using Python?

Sarika Singh

Sarika Singh

Updated on 15-May-2025 18:20:01

6K+ Views

The Python shutil module provides a number of functions for high-level operations on individual files and file collections. In this article, we will go through different methods of moving a file from one folder to another using Python. Using the OS Module The Python OS module gives users the ability ... Read More

How to remove swap files using Python?

Sarika Singh

Sarika Singh

Updated on 15-May-2025 18:12:01

731 Views

Swap files and temporary files are common byproducts of text editors such as Vim, Emacs or even modern IDEs. These files—often with extensions like .swp, .swo, .tmp or .bak are used to store session data or backup content temporarily. These are useful during editing sessions in which they can clutter ... Read More

How to create an empty file using Python?

Sarika Singh

Sarika Singh

Updated on 15-May-2025 18:08:07

23K+ Views

Creating an empty file is a common task in programming when we are initializing log files, setting up placeholders or working with automation scripts. Python provides several easy and flexible methods to create empty files. In this article, we'll go through different ways to create an empty file in Python. ... Read More

How to copy files from one folder to another using Python?

Sarika Singh

Sarika Singh

Updated on 15-May-2025 17:52:03

45K+ Views

We can easily check the Odd or Even by using conditional statements. We can divide the number by 2, then check whether the remainder is 0 or not. If 0, then it is even. We can also perform the AND operation ... Read More

How to know/change current directory in Python shell?

Sarika Singh

Sarika Singh

Updated on 15-May-2025 17:51:53

40K+ Views

A portable method of interacting with the operating system is offered through the OS Python Module. This module is a part of the default Python library, which contains tools for locating and modifying the working directory. When we are working in the Python shell or scripting environment, it's important to ... Read More

How to list non-hidden files and directories in windows using Python?

Sarika Singh

Sarika Singh

Updated on 15-May-2025 15:26:41

1K+ Views

Listing files and directories using Python is a common task in many applications, from file management tools to automated scripts. However, when we are working on the Windows Operating System, the hidden files and folders are marked using specific file attributes, which can clutter the output if not handled properly. ... Read More

Advertisements