0 votes
in Python by
How to handle data in a file in Python?

1 Answer

0 votes
by

Data from an opened file can be read using any of the methods: read, readline and readlines.

Data can be written to a file using either write or writelines method.

A file must be opened, before it is used for reading or writing.

Example: Reading a file

fp = open('temp.txt', 'r')   # opening

content = fp.read()          # reading

fp.close()                   # closing

Related questions

0 votes
asked Jan 1, 2021 in Python by SakshiSharma
0 votes
asked Jan 13, 2021 in Python by SakshiSharma
...