Reading, Writing and Opening a file in Python

0
245

To open a file in python one needs no hassle simply using a code as illustrated below can solve the issue

file in python
file in python

How to open a file Using Python

with open('demofile.txt', 'r') as f:
    data = f.read()

How to write a file Using Python

with open('demofile.txt', 'w') as f:
    data = 'the nature of the web'
    f.write(data)

the first code snippet opens open() and read .r the file while the second snippet writes .wdata” into the file “demofile.txt

LEAVE A REPLY

Please enter your comment!
Please enter your name here