How to read data from a text file using Python?

0 votes
Hi. I am trying to write a Python script to read the contents from a file and then print it. How can I do this?
May 12 in Python by Rajat
38 views

1 answer to this question.

0 votes

Refer to the below example where the filename is ‘data.txt’

file=open('data.txt','r+')
last_date=(file.read())
print(last_date)

I am just mentioning the file name because the script and the file are in the same directory. Suppose they are in a different directory then you should mention the path and then the read the file. 

answered May 12 by Sushma

Related Questions In Python

0 votes
1 answer

How to use read a WSDL file from the file system using Python suds?

Hi, good question. It is a very simple ...READ MORE

answered Jan 21 in Python by Nymeria
• 3,520 points
473 views
0 votes
1 answer

How to create and read from a temporary file in Python?

Hi, there is a very simple solution ...READ MORE

answered Jan 29 in Python by Nymeria
• 3,520 points
67 views
0 votes
1 answer

How do you read from a file using file handling in python?

To read from a file you can ...READ MORE

answered Jul 30 in Python by Mohammad
• 3,060 points
27 views
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6 in Python by Neha
• 330 points

edited Jul 8 by Kalgi 232 views
+4 votes
6 answers
0 votes
1 answer

How to write data to a file in Python?

Refer to the below code. data=’whatever your data ...READ MORE

answered May 12 in Python by Shaam
30 views
0 votes
1 answer

How to print the index of a Pandas Dataframe?

You can do this using the code ...READ MORE

answered May 12 in Python by Usha
48 views