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 is the difference between Python\'s re.search and re.match?
In Python, Regular expressions (RegEx) are sequences of characters that define search patterns. The re module provides several functions to work with patterns in text for tasks like string matching, validation, and manipulation. The most commonly used functions are re.match() and re.search(). Both check for pattern presence but differ in where they look for matches within a string. The re.match() Method The re.match() method checks if the beginning of a string matches the specified pattern. It returns a match object if found at the start, otherwise returns None. Syntax re.match(pattern, string, flags=0) ...
Read MoreHow to perform different commands over ssh with Python?
When we want to remotely access and execute commands on another machine, we use the paramiko library in Python. Paramiko is a third-party library that enables secure communication with remote machines using the SSH (Secure Shell) protocol. It allows us to execute commands, transfer files, and perform other remote tasks programmatically. To use the Paramiko library, first we need to install it ? pip install paramiko Basic SSH Connection and Command Execution Here's how to connect to a remote server via SSH and execute multiple shell commands ? import paramiko # ...
Read MoreHow to copy a file to a remote server in Python using SCP or SSH?
When we want to transfer files from our local system to a remote server securely, Python provides several ways to do file transfer using the Paramiko and SCP libraries. These libraries support SSH-based file transfer, which is secure and reliable. Installing Required Libraries Before we start with file transfer, we need to install the required libraries ? pip install paramiko scp Understanding SCP and SSH Paramiko is a third-party Python library that provides SSH and SFTP functionality using the SSHv2 protocol. SCP stands for Secure Copy Protocol, which copies files between computers over ...
Read MoreHow to get the maximum file name length limit using Python?
In Python, when performing file operations such as creating or renaming files, one of the limitations is the maximum length limit of a file name. When we exceed this limit, it results in errors such as OSError: [Errno 36] File name too long. Using os.pathconf() Function In Python, the os.pathconf() function is used to get system-specific configuration values related to files and directories. This function helps in checking limits such as the maximum file name length or the maximum path length allowed by the file system. Syntax Following is the syntax of the os.pathconf() function − ...
Read MoreWhat is the maximum file size we can open using Python?
In Python, there is no fixed maximum file size that we can open. Python can open files of any size as long as the operating system and file system support it and there is enough memory and disk space available. The limit of maximum file size comes with the system architecture, i.e., 32-bit, 64-bit, the file system, such as FAT32, NTFS, ext4, and how the file is processed in the code. System and File System Limits Following are the system and file system limits ? FAT32 − Maximum file size: 4 ...
Read MoreHow to extract all the .txt files from a zip file using Python?
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 MoreHow are files extracted from a tar file using Python?
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 MoreHow are files added to a tar file using Python?
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 MoreHow to create a zip file using Python?
ZIP is a widely used file format that compresses one or more files into a single archive file. This file format helps to reduce storage space and simplifies sharing or save backup of large data files. ZIP archives usually have a .zip file extension and are commonly used across different platforms. Compressed ZIP files reduce the size of the original directory by applying a compression algorithm. This results in faster file sharing over a network as the size of the ZIP file is significantly smaller than the original file. Python Modules for Creating ZIP Files In Python, ...
Read MoreHow to create a tar file using Python?
TAR stands for Tape Archive Files. Tar files are archive files that allow us to store multiple files and directories in a single file. Open-source software is commonly distributed using tar files. Tar files typically end in .tar and can be compressed using tools such as gzip, resulting in files ending with .tar.gz. File Modes for Creating Tar Files Here are the available file modes to create tar files using Python's tarfile module ? "w": Write a tar archive without compression. "w:gz": Write a gzip-compressed archive. "w:bz2": Write a ...
Read More