With Context Manager in Python
With Context Manager in Python In this Article i will show you how to use the “with” Keyword to create a text file and then write something into the File
Sample Code
- Using the “with ” Keyword “
- Open and create a new file called ” Sample.txt” and then assign “w” to write something into the File
- Use the Write Function “write() ” and then write text or number you want into the file you ave just created
with open("sample.txt","w") as myfile: myfile.write('Hi There')
Results
Check out Multiple iteration in Python here
Leave a Reply