Skip to content
KnpCode
Java, Spring, BigData, Web development tutorials with examples
Skip to content
  • Ubuntu
  • Big Data
    • Hadoop Tutorials
  • Java
    • Core Java Tutorials – Beginner
    • Core Java Tutorials – Advanced
    • Java Programs
  • spring
    • Spring Framework
    • Spring Boot Tutorial
Home Posts tagged "Python IO"

Tag: Python IO

How to Copy File in Python

UshaK February 4, 2021 February 4, 2021python Python, Python IO 0

In this post we’ll see different ways you can copy a file in Python. 1. A simple way to copy a file in Python is to use read() method to read a file once you have a file object and then write the content to another file. Following Python program…

Continue reading

tempfile Module in Python – Create Temporary File and Directory

UshaK January 10, 2021 February 11, 2021python Python, Python IO 0

In this tutorial we’ll see how to create temporary file and directory in Python. You may require a temporary file to store some data temporarily while the application is running which can be safely deleted automatically when the task is done. tempfile module in Python In Python, tempfile module has…

Continue reading

fnmatch Module in Python – File Name Pattern Matching

UshaK January 10, 2021 February 11, 2021python Python, Python IO 0

In this post we’ll see how to use functions in fnmatch module in Python which provides support for Unix shell-style wildcards. Note that Unix shell-style wildcards are not the same as regular expressions, the special characters used in shell-style wildcards are: Pattern Meaning * matches everything ? matches any single…

Continue reading

Python Program to Delete Files Having a Specific Extension

UshaK December 25, 2020 February 11, 2021python Python, Python IO 0

In this tutorial we’ll see how to write a Python program to delete all the files having a specific extension. 1. Using os.listdir() In os module in Python there is a function listdir() that returns a list containing the names of the entries in the directory. You can iterate that…

Continue reading

How to Delete File and Directory in Python

UshaK December 16, 2020 February 10, 2021python Python, Python IO 0

In this tutorial we’ll see how to delete (remove) a file or directory in Python, even recursively deleting a directory. In Python there are different functions and methods in built-in modules that can be used for the purpose. Deleting a single file– os.remove(), os.unlink(), pathlib.Path.unlink() Deleting an empty directory– os.rmdir(),…

Continue reading

Python Program to Check File or Directory Exists

UshaK December 15, 2020 February 10, 2021python Python, Python IO 0

In this tutorial we’ll see how to check if a file or directory exists in Python. Table of contents Using os module Using try-except with open() function Using pathlib module 1. Using os module In os.path module in the Python standard library there are following methods that can be used…

Continue reading

Input from User in Python – input() function

UshaK December 11, 2020 February 9, 2021python Python, Python IO 0

If you have to take user input from keyboard in Python that can be done using input() function. Python input() function takes the entered value and returns it as a string once user presses Enter. Table of contents Syntax of input() function User input in Python example Input as number…

Continue reading

Python Program to Append to a File

UshaK December 10, 2020 February 9, 2021python Python, Python IO 0

In the post Python Program to Write a File we saw options to write to a file in Python but that has the drawback of overwriting the existing file. If you want to keep adding content to an existing file you should use append mode to open a file. In…

Continue reading

Python Program to Write a File

UshaK December 9, 2020 February 9, 2021python Python, Python IO 0

In this tutorial we’ll see different options to write to a file in Python. Using write() method you can write the passed string to a file. Using writelines(lines) method you can write a list of lines. Writing file in binary mode. 1. Using write() method for file writing in Python…

Continue reading

Python Program to Read a File

UshaK December 8, 2020 December 16, 2020python Python, Python IO 0

In this tutorial we’ll see different options to read a file in Python. 1. Using read() method you can read the whole file. 2. Using readline() and readlines() methods you can read file line by line. 3. More efficient way to read file line by line is to iterate over…

Continue reading

12
Privacy Policy | Disclaimer
Powered by Nirvana & WordPress.