Articles on Trending Technologies

Technical articles with clear explanations and examples

How to monitor Python files for changes?

Niharikaa Aitam
Niharikaa Aitam
Updated on 24-Mar-2026 2K+ Views

Monitoring Python files for changes is essential in many development and automation scenarios such as triggering automatic reloads, running tests, or updating services when the source code is modified. This is particularly useful in web development, machine learning pipelines or custom tooling where real-time responsiveness to file updates is beneficial. One effective way to achieve this in Python is by using the watchdog library which is a simple and efficient tool that listens for file system events like creation, modification, and deletion. With watchdog library, developers can set up observers that watch specific directories and respond to the ...

Read More

How to write into a file from command line using Python?

Niharikaa Aitam
Niharikaa Aitam
Updated on 24-Mar-2026 3K+ Views

Through the command line, we can easily create dynamic scripts that modify or generate files based on user input. This functionality is useful for generating logs, exporting data, or saving outputs from calculations. The following are the basic steps we need to follow to write data into a file from the command line ? Accept the file name and optional data from the command line. Open the specified file in write mode. Write the content to the file. Handle possible errors such ...

Read More

How to read a file from command line using Python?

Niharikaa Aitam
Niharikaa Aitam
Updated on 24-Mar-2026 12K+ Views

Reading files from the command line is a common task in many Python scripts and automation workflows. Whether we're building a simple utility to process text files or developing a complex data analysis tool, being able to accept file input directly from the command line enhances the flexibility and usability of our program. Python provides built-in modules such as sys and argparse that make this task straightforward and efficient. In this article, we'll explore different methods to read a file from the command line using Python. Using sys.argv In Python, sys.argv is a list provided by the ...

Read More

How can I source a Python file from another Python file?

Niharikaa Aitam
Niharikaa Aitam
Updated on 24-Mar-2026 6K+ Views

In Python, sourcing one Python file from another enables code reuse and modular programming. This article explores different methods to import and use Python files in your scripts. Understanding Python File Importing Python importing allows you to use functions, classes, and variables defined in one file within another. This promotes code reusability and helps organize code into logical modules based on functionality. Using the import Statement The import statement is the most common way to include external Python files or modules in your script. Following is the syntax ? import module_name ...

Read More

How does underscore \"_\" work in Python files?

Niharikaa Aitam
Niharikaa Aitam
Updated on 24-Mar-2026 757 Views

In Python, the underscore (_) is a special character with different meanings based on how and where it is used. It plays a significant role in readability, naming conventions, and interpreter behavior. In this article, we will discuss different scenarios of using the Underscore(_) in Python. Single Underscore _ as Throwaway Variable The single underscore (_) is commonly used as a throwaway variable when you don't need to use a particular value in loops or unpacking operations. Ignore Values in Loops When we don't care about the loop variable value, we use _ to indicate this ...

Read More

How can I make one Python file run another?

Niharikaa Aitam
Niharikaa Aitam
Updated on 24-Mar-2026 61K+ Views

In Python, it is often necessary to execute another file. This is common in cases such as running helper scripts, triggering workflows, or executing test cases. Python provides several ways to execute one file using another. Depending on the requirement, whether we want to reuse functions, execute a file directly, or run it as a subprocess. Let us look at these solutions one by one ? Understanding Python Script Execution Before proceeding with how to run one Python file from another, it's important to understand how Python scripts are executed. When we run a Python file ...

Read More

How do I copy a binary file in Python?

Niharikaa Aitam
Niharikaa Aitam
Updated on 24-Mar-2026 4K+ Views

In Python, you may need to duplicate binary files such as images, videos, or executables. This article explores efficient methods for copying binary files in Python, covering both built-in functions and manual approaches. What is Binary Format? Binary format stores data as raw byte sequences (0s and 1s) rather than readable text characters. Binary file copying duplicates files byte-by-byte without interpreting content, essential for non-text files like images (.jpg, .png), audio/video (.mp3, .mp4), executables (.exe), and PDFs. Using shutil.copy() The shutil.copy() function copies file contents and basic permissions from source to destination ? Syntax ...

Read More

How to find all files in a directory with extension .txt in Python?

Niharikaa Aitam
Niharikaa Aitam
Updated on 24-Mar-2026 2K+ Views

Searching for specific files in a directory is a common task that can be accomplished using different tools in Python. In this article, we will see how to find all the files in a directory with extension .txt using Python. Here are different approaches, let's see each one in detail ? Using os.listdir() The os.listdir() function from Python's built-in os module returns a list of file and directory names in the given directory path. Example In this example, we use os.listdir() with list comprehension to filter files ending with ".txt" ? import os ...

Read More

What is the common header format of Python files?

Niharikaa Aitam
Niharikaa Aitam
Updated on 24-Mar-2026 15K+ Views

The common header format of Python files is a simple and essential element that provides context and documentation. In Python, we commonly use a docstring as the header format − a special comment enclosed within triple quotes placed at the beginning of the script. Standard Header Structure The standard Python file header uses a docstring with key information about the script ? """ File: filename.py Author: Your Name Date: Date of creation/modification Description: A brief explanation of what this script does. """ Header Components File: The name of the Python file (e.g., ...

Read More

What do the python file extensions, .pyc .pyd .pyo stand for?

Niharikaa Aitam
Niharikaa Aitam
Updated on 24-Mar-2026 9K+ Views

Python uses different file extensions to distinguish between various types of files in the Python ecosystem. Understanding these extensions helps developers work more effectively with Python code, modules, and compiled bytecode. Python File Extensions Overview The most common Python file extensions and their purposes are ? .py: Standard Python source code files .pyc: Compiled bytecode files for faster loading .pyo: Optimized bytecode files (deprecated in Python 3.5+) .pyd: Python extension modules on Windows (similar to .dll files) .pyw: Windows GUI scripts that run without a console window .py Files The .py extension identifies ...

Read More
Showing 7731–7740 of 61,297 articles
« Prev 1 772 773 774 775 776 6130 Next »
Advertisements