
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 26504 Articles for Server Side Programming

11K+ Views
When working with files in Python, it's often useful to sort them based on their creation time. For example, to find the most recently added file or to process files in the order they were created then we need sort them by the creation date. Python provides built-in methods such as os and os.path which makes it easy to retrieve file metadata and sort directory contents accordingly. In this article, we will explore all the different method to sort the directories based on the creation date in Python - Using os.listdir() with sorted() and os.path.getctime() ... Read More

40K+ Views
A portable method of interacting with the operating system is offered through the OS Python Module. This module is a part of the default Python library, which contains tools for locating and modifying the working directory. When we are working in the Python shell or scripting environment, it's important to know which directory we're currently working in. This is known as the current working directory. We can change the current working directory to navigate our file system programmatically. In this article, we will see how to change the current working directory in the Python shell. Getting the current working directory ... Read More

1K+ Views
In Python programming, it is important to check whether a given path points to a file or a directory. This check is very useful before performing operations such as reading, writing or listing contents. In this article, we’ll see the different methods to identify file types using Python. Why should we check the file type? Before interacting with a file path, it is important to confirm the type of the file to make sure that the code behaves as expected. If the code treats a directory as a file or file as a directory, it can cause errors or data ... Read More

3K+ Views
When working with files in Python programming, the common tasks we can perform are reading data, writing logs or processing content. If the files are not managed in a proper way then it leads to issues such as resource leaks, file corruption or unexpected errors. In this article, we'll explore the different ways to safely open and close files in Python. Why file safety is important? When we open a file in python then the operating system will allocate resources to handle the file. If the file is not closed correctly, then those resources might not be released properly which ... Read More

31K+ Views
We may see many situations in Python where we need to remove all the files from a particular folder. For example, we may need to perform cleaning up temporary logs, resetting application data, or managing output directories. This can be done by simply pointing to the folder and deleting files manually, but it is inefficient, especially when working with large-scale or automated scripts. In such cases, we can ensure a clean and reliable way of deleting files by using the built-in modules like os, pathlib, or shutil, which allow us ... Read More

35K+ Views
In Python, it is a common scenario that the files we want to work with should be placed in the same folder as the script itself. Simply we with the reference of a filename like "data.txt" may not always work as expected, especially when the script is executed from a different working directory. The best way is to place the scripts in the actual location using the __file__ variable along with the os or pathlib modules. In this article, we are going to see the different approaches to open a file in the same directory as a Python script. Using ... Read More

3K+ Views
In Python, when working with files and directories, we may often need to access the parent directory of a given path, especially when going through a file system or managing relative paths in a project. In this article, we are going to explore the different methods available in Python to get the parent directory of the current or any specific path. Using os Module One of the commonly used methods to interact with the file system in Python is using the os module. This module provides various utilities to work with file paths and directories. To get the parent directory, ... Read More

13K+ Views
In Python, when working with files and directories, we may often need to get a list of subdirectories within a specific location, especially the current working directory. In this article, we are going to use the different methods available in Python to get a list of all subdirectories in the current directory. Using os Module While working with files, one of the most widely used approaches is using os module. This module provides a way to interact with the operating system to perform tasks such as navigating directories, reading file structures, and more. In this module, we have a ... Read More

19K+ Views
The path of a current file is defined with the help of directory hierarchy; and it contains the backtracked path from the current file to the root directory this file is present in. For instance, consider a file “my_file” belongs to a directory “my_directory”, the path for this file is defined as given below ./my_directory/my_file The directory, sub-directory and the file are all separated using the “/” separator in the path. Therefore, to get current file's full path, you can use the os.path.abspath() function. If you want only the directory path, you can call os.path.dirname() method. Using os.path.abspath() Method ... Read More

2K+ Views
In Python, the __init__.py is a special file in python packages. It is used to indicate that how a directory should be treated. When Python encounters a directory during an import, first it looks for the __init__.py file to determine how to initialize the package and what code should be executed during the import. In python 3.3 version, the __init__.py was introduced with the feature of creating a package with the namespace. Let's understand the purpose of the __init__.py file - It makes the directory a Python package so the interpreter can find the module ... Read More