Hands-On Python Programming For Beginners by Publishing AI

Hands-On Python Programming For Beginners by Publishing AI

Author:Publishing, AI
Language: eng
Format: epub
Publisher: AI Publishing LLC
Published: 2021-06-11T00:00:00+00:00


To read a text file with Python, you first have to open the file with read permissions and then call the read() method using the file handler object. The following script reads a file named “my_text.txt.”

Script 6:

file_handle_text=open("E:/Datasets/my_text.txt","r+")

file_content=file_handle_text.read()

print(file_content)

The output shows that the file contains three lines of text. You can open your text file if you want.

Output:

hello there

Welcome to Python from zero to hero

You will learn Python in this book.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.