Found 27104 Articles for Server Side Programming

What are the modes a file can be opened using Python?

Rajendra Dharmkar
Updated on 22-Aug-2023 10:21:36

5K+ Views

In the realm of Python programming, working with files demands a thorough grasp of the various modes in which files can be opened. The mode of file opening dictates the operations that can be performed on the file, be it reading, writing, or a combination of both. Python offers a wide array of modes tailored to diverse use cases and requirements. Whether you seek to read data from a file, write data to it, or simultaneously undertake both operations, selecting the appropriate file opening mode holds paramount importance for seamless file handling. In this comprehensive article, we embark on a ... Read More

How to check file last access time using Python?

Sarika Singh
Updated on 18-Aug-2022 08:29:35

2K+ Views

The file last access datetime in Python can be obtained in a number of different ways. The following OS module methods will be used to obtain the file last access time in Python. Using os.path.getatime() Method In Python, we can use the os.path.getatime() method to retrieve a path's most recent access time. The path that we need to verify for the access time is taken by this approach. The amount of time since the epoch is returned as a floating point value. It throws one OSError if the requested path cannot be reached or if it does not exist. Syntax ... Read More

How to remove swap files using Python?

Sarika Singh
Updated on 17-Aug-2022 14:03:51

549 Views

This Python article will teach you how to recursively remove all files in a folder that have a particular extension. The application will remove all files with the supplied extension inside the folder when we give it the folder path and file extension. Example - using file.endswith() method The steps involved to remove swap files are as follows − Import the _os _module and _listdir _from it. To view a list of all files in a certain folder, use _listdir, and to delete a file, use _os module. The path to the folder containing all files is called folderpath. ... Read More

How to remove hidden files and folders using Python?

Rajendra Dharmkar
Updated on 22-Aug-2023 10:13:43

2K+ Views

In the domain of file and folder manipulation, it is found that hidden files and folders can be a source of inconvenience, chaos and confusion, particularly when they are not supposed to be accessible and visible to the end-users. It is a common practice to keep hidden files and folders in a directory that often start with a dot (.) on Unix-based systems (e.g., Linux, macOS) or are designated as hidden on Windows systems. Deleting these hidden files and folders manually can be a tedious task; in this context, Python can be of great help! In this article, we will ... Read More

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

Rajendra Dharmkar
Updated on 11-Sep-2023 17:18:17

818 Views

When coming across and dealing with file and directory operations within the Windows environment using Python, it's not uncommon to come across the hidden files and directories. These hidden files and folders usually are system files and are purposefully kept out of sight from users. Among these, you might uncover configuration files, those fleeting temporary files, and an array of system−related data. However, in most cases, you may need to list only the non−hidden files and directories to avoid disarray and focus on relevant data. Prepare yourself for a journey through this all−encompassing article. What lies ahead is an exploration ... Read More

How can I list the contents of a directory in Python?

Sarika Singh
Updated on 17-Aug-2022 13:20:42

5K+ Views

A computer's file system's directory is an organisational feature used to store and locate files. A tree of directories is created by organising directories hierarchically. There are parent-child relationships in directories. A folder can also be used to refer to a directory. Python has accumulated a number of APIs that can list the directory contents over time. Useful functions include Path.iterdir, os.scandir, os.walk, Path.rglob, and os.listdir. We could need a list of files or folders in a given directory in Python. You can accomplish this in a number of ways. OS module A function that returns a list of the ... Read More

How to ignore hidden files using os.listdir() in Python?

Rajendra Dharmkar
Updated on 11-Sep-2023 17:06:37

4K+ Views

While working with folders or directories in Python, it's a routine experience to encounter hidden files and folders. Hidden files and folders are system files that are not intended to be visible to users, which may include configuration files, temporary files, and system−related data. In many such situations, you may want to ignore these hidden files and only work with the visible ones to avoid clutter and improve the efficiency of your code. In this in−depth article, we will explore different methods to ignore hidden files using the "os.listdir()" function in Python. We will also provide step−by−step explanations and code ... Read More

How to open new pseudo-terminal pair using Python?

Rajendra Dharmkar
Updated on 20-Jul-2023 13:05:33

444 Views

In the realm of Python programming, there arise times and scenarios where we need to interact and work with a terminal environment programmatically. Whether it is required to automate terminal-based tasks or to simulate user input, having the ability and skill to successfully create a new pseudo-terminal pair can be incredibly useful. In this article, we will explore different approaches of how to open a new pseudo-terminal pair using Python and the pty module. So let us get started right away. We have included some code examples with easy-to-follow explanations to guide you through the process. Open a New Pseudo-terminal ... Read More

How to create an empty file using Python?

Sarika Singh
Updated on 17-Aug-2022 12:50:10

20K+ Views

Empty describes anything which contains nothing. Using a computer as an example, an empty file is one that has no data in it; it has 0 bytes and is in plain text format having no data kept in a file. Let us discuss various types of empty files that can be created using python. Creating an empty CSV file The plain text file format known as a CSV file (Comma Separated Values file) is used to structure tabular data in a particular way.It can only contain actual text data that is, printable ASCII or Unicode characters—because it is a plain ... Read More

How to find the mime type of a file in Python?

Rajendra Dharmkar
Updated on 11-Sep-2023 16:52:45

5K+ Views

In the domain of file handling and manipulation in Python, it is often critical to determine the MIME (Multipurpose Internet Mail Extensions) type of a file. MIME types are standardized labels used to identify the nature and format of a file's content. They play a crucial role in various applications, such as web development, email attachments, and data transmission over the internet. Being able to ascertain the MIME type of a file is vital for performing appropriate actions based on its content, such as validating, processing, or displaying it correctly. In this particular article, we will explore different methods to ... Read More

Advertisements