eith python code example

Example 1: with python

# file handling 
  
# 1) without using with statement 
file = open('file_path', 'w') 
file.write('hello world !') 
file.close() 
  
# 2) without using with statement 
file = open('file_path', 'w') 
try: 
    file.write('hello world') 
finally: 
    file.close() 
    
# using with statement 
with open('file_path', 'w') as file: 
    file.write('hello world !')

Example 2: with python

The 'with' statement is a new control-flow structure whose basic structure is:

with expression [as variable]:
    with-block