Python short course: File operations basics in Python

 The file operation is important in Python development. Some basics operations are below:



In [1]: with open('spam.txt', 'w') as file:
   ...:     file.write(('spam'*5)+'\n')
   ...: 

In [2]: with open('spam.txt', 'r') as file:
   ...:     text = file.read()
   ...: 
   ...: 

In [3]: text
Out[3]: 'spamspamspamspamspam\n'

Comments

Popular posts from this blog

Lab's weekly topic - week 50 2023 - Detailed explanation for encoder of U-Net

Lab's recommendation: Awesome books to learn machine learning and AI (continue updating)