Found 27104 Articles for Server Side Programming

How to write binary data to a file using Python?

Rajendra Dharmkar
Updated on 25-Jul-2023 09:59:05

26K+ Views

It is a common and routine task in Python; the act of writing binary data to a file when you need to save non-textual data such as images, audio files, or serialized objects. In this article, we will explore various ways how you can write binary data to a file using Python and provide you with code examples followed by comprehensive explanations to help you grasp the concept. To write binary data to a file in Python, you can follow these steps: Open the File in Binary Mode First, you should proceed to open the file in ... Read More

How to set creation and modification date/time of a file using Python?

Rajendra Dharmkar
Updated on 25-Jul-2023 09:41:43

6K+ Views

The creation and modification datetime of a file in Python are defined as the timestamps associated with the events of when the file was created and when it was last modified. Creation datetime: It is defined as the timestamp when a file was initially created or added to the file system. Modification datetime: It is defined as the timestamp when the file's content was last modified or updated. These datetimes can provide a lot of information such as the file's age, recent changes, or when it was first introduced. In Python, you can fetch the ... Read More

How to remove a file using Python?

Rajendra Dharmkar
Updated on 24-Jul-2023 20:42:18

251 Views

There will be times when we need to remove files programmatically in Python. Removing files, in this context, is the act of deleting or erasing files from a computer's file system using Python programming language. You must know that when you remove a file, it is permanently deleted from the storage location; this frees up disk space and makes the file inaccessible. Python has a number of modules and functions, such as os.remove() or os.unlink(), that permit you to interact with the operating system and remove files using code. This functionality is particularly useful when we want to automate tasks, ... Read More

How to create a unique directory name using Python?

Rajendra Dharmkar
Updated on 18-Feb-2020 04:56:12

804 Views

You can use the tempfile module to create a unique temporary directory in the most secure manner possible. There are no race conditions in the directory’s creation. The directory is readable, writable and searchable only by the creating user ID. Note that the user of mkdtemp() is responsible for deleting the temporary directory when done with it. To create a new temporary directory, use it as follows −import tempfile _, temp_dir_path = tempfile.mkdtemp() # Do what you want with this directory # And remove the directory when doneNote that you need to manually delete this directory after you're done with ... Read More

How to create a unique temporary file name using Python?

Rajendra Dharmkar
Updated on 18-Feb-2020 04:54:54

619 Views

You can use the tempfile module to create a unique temporary file in the most secure manner possible. There are no race conditions in the file’s creation. The file is readable and writable only by the creating user ID. Note that the user of mkstemp() is responsible for deleting the temporary file when done with it. To create a new temporary file, use it as follows −import tempfile _, temp_file_path = tempfile.mkstemp() print("File path: " + temp_file_path)Note that you need to manually delete this file after you're done with it.

How to rename multiple files recursively using Python?

Rajendra Dharmkar
Updated on 25-Jul-2023 09:36:59

3K+ Views

The act of renaming multiple files recursively in Python can be a useful task when it is required to change the names of multiple files within a directory and its subdirectories. If you need to replace certain characters, add prefixes or suffixes, or completely change the file names, Python has powerful tools to accomplish such operations. In this article, we explore a few different approaches to renaming multiple files recursively using Python. We consider some code examples, each demonstrating a unique method to achieve this task. So let us get started right away and learn how to rename multiple files ... Read More

How to rename directory using Python?

Rajendra Dharmkar
Updated on 25-Jul-2023 09:31:07

8K+ Views

There are times when you want to organize your files or update the directory names to better reflect their contents. In such scenarios, the operation of renaming directories becomes helpful and it is a common task that we often encounter in Python file management. There is provision of several modules and methods in Python that makes renaming directories an easy task. In this article, we explore different ways how you can rename directories using Python code. You will learn this skill by practicing the code examples and explanations discussed in this article. Making Use of the OS Module ... Read More

How to create a filesystem node using Python?

Rajendra Dharmkar
Updated on 17-Jul-2023 15:49:14

565 Views

In the realm of Python programming, a filesystem node holds significant prominence as it encompasses the essence of file and directory representation within the intricate file system. This construct acts as a means to interact with files and directories programmatically. Each node bears multiple attributes like names, sizes, permissions, and timestamps. The widely used Python modules, such as "os" and "pathlib, " serve as the conduits through which one may interact with these entities, the filestystem nodes and even modify them when required. Filesystem nodes can be created, renamed, deleted, and navigated to access their contents. These nodes make ... Read More

Querying SAP database using Python

V Jyothi
Updated on 30-Jul-2019 22:30:20

880 Views

Python is one of the most used object-oriented programming languages which is very easy to code and understand.In order to use Python with SAP, we need to install Python SAP RFC module which is known as PyRFC. One of its available methods is RFC_READ_TABLE which can be called to read data from a table in SAP database.Also, the PyRFC package provides various bindings which can be utilized to make calls either way. We can use to make calls either from ABAP modules to Python modules or the other way round. One can define equivalent SAP data types which are used ... Read More

How to create and use a named pipe in Python?

Rajendra Dharmkar
Updated on 17-Jul-2023 15:38:14

9K+ Views

Consider a pipeline that allows for seamless data flow and communication between various components of a complex system. Named pipes are similar conduits in Python programming, making it easier for programs to communicate with each other and other processes. Named pipes, which are also referred to as FIFOs (First-In, First-Out), are a powerful way to exchange data between processes on the same system or even between systems. In this article, we will take a journey into Python to learn how to create and use named pipes. We'll unwind the step by step process of making a named pipe, writing and ... Read More

Advertisements