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

0 votes
What is the syntax to write in a text file?
Jul 22 in Python by Waseem
• 4,160 points
23 views

1 answer to this question.

0 votes

To read from a file you can use the following command.

#file.read()
file = open('filename', "r")

To write into a file, you can use the following code.

file = open("filename", "w")
file.write("what you want to write")
file.close()

answered Jul 30 by Mohammad
• 2,820 points

Related Questions In Python

0 votes
1 answer

In Python, how do I read a file line-by-line into a list?

with open(fname) as f:     content = f.readlines() # you ...READ MORE

answered Oct 9, 2018 in Python by SDeb
• 13,160 points
105 views
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,500 points
375 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,500 points
44 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 168 views
+4 votes
6 answers
0 votes
1 answer
0 votes
1 answer