• 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 Using the write() function to write a list to a file in Python The write() function is used to write contents to a […]

  • 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 \ […]

  • Python read text file line by line
    13 May

    Read text file line by line in Python

    Learn about how to read text file line by line in Python.

  • 26 March

    Python list files in directory

    In this post, we will see how to list all files in a directory in Python. There are multiple ways to list all files in a directory in Python. Using os.walk Python os module provides multiple function to get list of files. List all files in directory and its subdirectories using os.walk(path). It iterates directory […]

  • 23 March

    Python write to text file

    In this post, we will see how to write to a text file. There are multiple modes in which you can write to text file. Create txt file(‘x’) It will open the file in 'X' mode which will create new file and return error in case file already exists. [crayon-60c7705a75b34806149689/] Here is content of fruits.txt. […]

  • 23 March

    Python read file into string

    In this post, we will see how to read a file into a string variable. There are multiple ways to read file into String in Python. Using read() method Here are the steps to read file into string in python. Open the file in read mode using open() method and store it in variable named […]