2 ways Python Reads, Writes and Opens a file

0
584
file in Python
file in Python

When you like python opens a file needs no hassle any longer simply use code as illustrated below can solve the issue in addition you can also python reads and writes to same file in same way

Opening a file in python
file in python

Opening a file in python using this simple way

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