Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

python with

# With is used for better and more readable file handling.
# Instead of having to open and close the file:
file_handler = open('path', 'w') 
file_handler.write('Hello World!') 
file_handler.close() 

# You can use with which will close the file for you at the end of the block:
with open('path', 'w') as file_handler:
  file_handler.write('Hello World!') 

# Another common use is with pickle files:
with open('pickle_path.pkl', 'rb') as file_handler:
  file_contents = pickle.load(file_handler)
 
PREVIOUS NEXT
Tagged: #python
ADD COMMENT
Topic
Name
9+2 =