• 19 May

    Print Current Directory in Python

    In this post, we will see how to print current directory in Python. Files and Directories in Python A computer system uses directories to store and organize files. Every file is present in some directory. There is a root folder at the top of the hierarchy, and every directory is a child of this root. […]

  • Python copy file to another directory
    17 January

    How to copy file to another directory in Python

    In this article, we will see different ways to copy file to another directory in Python. We can read and write files in Python. We can also work with paths and directories using different libraries. Ways to copy file to another directoy in Python We will discuss different methods to copy file from one destination […]

  • Copy file Python
    12 January

    How to Copy File in Python?

    Python provides us with many modules and functions to perform file operations. In this article, we will discuss different ways to copy file in python. For this, we will use the os module, shutil module, and subprocess module. We will also discuss advantages and disadvantages for each approach as file operations are costly in terms […]

  • Python absolute path
    17 November

    Get Absolute Path in Python

    We often use files to store the outputs of our programs in permanent storage. Generally, we work with relative paths of files in our programs. In this article, we will discuss two ways to get the absolute path to a file in python from its relative pathname. What is an absolute path to a file? […]

  • Python create file if not exists
    06 November

    Create File if Not Exists in Python

    1. Introduction to the Problem Statement In Python, ensuring that a file is created only if it does not already exist is a common operation in many applications like data logging, file manipulation, or when working with temporary files. This operation is crucial to prevent overwriting existing data. Our task is to create a file […]

  • Python overwrite file
    06 November

    Overwrite file in Python

    File Handling in Python We can read and write content to files in Python. We use the open() function to create files and specify the path and mode for the required file. This creates a file handling object that handles different file operations. Ways to overwrite file in Python To overwrite a file, we need […]

  • Iterate through files in directory in Python
    30 August

    Iterate through files in directory in python

    A directory, as its name implies, is a place where sub-directories are created and files are stored. A directory with no parent is referred to as the root directory which is usually the main directory. This tutorial demonstrates the different ways available to iterate through files in directory in Python. Python provides the os module […]

  • Write a list to a file in Python
    12 June

    Write a List to A File in Python

    Python allows us to work with different data structures and write them to an external file. In this tutorial, we will learn how to write a list to a file in Python. If you want write list to CSV file, you can refer write list to CSV in Python. Using the write() function to write […]

  • Get filename from path in Python
    21 May

    Get filename from Path in Python

    There are different ways to define the path of the file. In Windows, the path separator for a file can be either a backslash or a forward slash. The ntpath module of Python will work on all platforms for all paths. The forwardslash / is used for UNIX and MacOS operating system and backslash \ […]