Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Articles on Trending Technologies
Technical articles with clear explanations and examples
What are .pyc files in Python?
We usually write programs in Python and save the file with .py extension. However, there is another file type called .pyc, which is automatically generated by the Python interpreter while executing the source code. What is a .pyc File? When you execute a Python program, the Python interpreter doesn't directly execute the .py file; instead, it parses the source code, compiles it into bytecode (a low-level representation of the Python source code), and stores it as the .pyc file. Further, this bytecode is executed with the Python Virtual Machine (PVM). A .pyc file is usually created when ...
Read MoreHow to set creation and modification date/time of a file using Python?
The creation and modification datetime of a file in Python are defined as the timestamps associated with 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 provide valuable information such as the file's age, recent changes, or when it was first introduced. In Python, you can retrieve these timestamps using functions like os.path.getctime() and os.path.getmtime(), and ...
Read MoreHow to create a unique directory name using Python?
Creating unique directory names is essential when working with temporary files or avoiding naming conflicts. Python's tempfile module provides a secure way to create unique temporary directories with proper permissions. Using tempfile.mkdtemp() The mkdtemp() function creates a temporary directory in the most secure manner possible. There are no race conditions in the directory's creation, and it's readable, writable, and searchable only by the creating user ID ? import tempfile import os # Create a unique temporary directory temp_dir_path = tempfile.mkdtemp() print(f"Created directory: {temp_dir_path}") # Check if directory exists print(f"Directory exists: {os.path.exists(temp_dir_path)}") # Clean ...
Read MoreHow to rename multiple files recursively using Python?
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 different approaches to renaming multiple files recursively using Python ? Using os.walk() to Traverse the Directory Tree The os.walk() function from the os module is used to traverse the directory tree and access files and directories within ...
Read MoreHow to create a filesystem node using Python?
A filesystem node represents any entity in the file system, such as files, directories, or symbolic links. Python provides powerful modules like os and pathlib to create and manipulate these filesystem nodes programmatically. Filesystem nodes have attributes like names, sizes, permissions, and timestamps. You can create, rename, delete, and navigate through them to perform operations like reading files, creating directories, and checking properties. Creating Directories Using os.mkdir() The os.mkdir() function creates a single directory ? import os # Create a single directory directory_path = "new_directory" os.mkdir(directory_path) print(f"Directory '{directory_path}' created successfully!") ...
Read MoreQuerying SAP database using Python
Python is one of the most widely used object-oriented programming languages, known for its simplicity and readability. When working with enterprise systems, connecting Python to SAP databases is a common requirement for data extraction and analysis. To connect Python with SAP systems, we need to install the PyRFC module, which provides Python bindings for SAP Remote Function Calls (RFC). This module enables seamless communication between Python applications and SAP systems. Installing PyRFC Before querying SAP databases, you need to install the PyRFC package and SAP NetWeaver RFC Library ? pip install pyrfc Note: ...
Read MoreHow to create and use a named pipe in Python?
Named pipes, also known as FIFOs (First-In, First-Out), are special files that enable inter-process communication in Python. Unlike anonymous pipes limited to parent-child processes, named pipes allow unrelated processes to exchange data seamlessly. Understanding Named Pipes Named pipes are special files that exist in the file system but don't store data permanently. They act as conduits where data flows from one process to another through system memory. A key characteristic is that they must be opened as either read-only or write-only, not both simultaneously. Creating a Named Pipe Use the os.mkfifo() function to create a named ...
Read MoreHow to Compose a Raw Device Number from the Major and Minor Device Numbers?
In low-level systems programming, device numbers play a crucial role in identifying and interacting with hardware devices. Every device connected to a computer system is assigned a unique pair of numbers: major and minor device numbers. Understanding how to compose a raw device number from these components is essential when working with device drivers or performing low-level device operations. Understanding Major and Minor Device Numbers In Linux kernel and Unix-like systems, major device numbers identify the device type or driver associated with a device, while minor device numbers specify a particular instance or unit of that device type. ...
Read MoreHow to create hardlink of a file using Python?
Hard links in Python allow you to create multiple names for the same file on the filesystem. When you modify content through one link, changes are reflected in all other hard links since they point to the same data. Python provides several methods to create hard links programmatically. Using os.link() Using os.system() with Shell Command Using subprocess.run() Using os.link() Method The most straightforward way to create a hard link in Python is using the os.link() method from the OS module. This method takes ...
Read MoreHow to get a file system information using Python?
File system information includes attributes and metadata associated with files or directories, such as size, available space, and usage statistics. Python provides several modules like os, shutil, and third-party libraries like psutil to retrieve this information programmatically. Using os.statvfs() for File System Statistics The os.statvfs() function returns detailed file system information as a statvfs_result object with various attributes ? import os # Use current directory for demonstration path = '.' # Retrieve file system information fs_info = os.statvfs(path) # Print key file system attributes print("File System Information:") print("Available File Nodes:", fs_info.f_favail) print("Total File ...
Read More