file - Python, open for writing if exists, otherwise raise error -


is there option can pass open() cause ioerror when trying write nonexistent file? using python read , write block devices via symlinks, , if link missing want raise error rather create regular file. know add check see if file exists , manually raise error, prefer use built-in if exists.

current code looks this:

device = open(device_path, 'wb', 0) device.write(data) device.close() 

yes.

open(path, 'r+b') 

specifying "r" option means file must exist , can read. specifying "+" means can write , positioned @ end. https://docs.python.org/3/library/functions.html?#open


Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -