Is this on some device like the Raspberry Pi? From the filename, it looks like this is a special – writing to it will control some device, rather than just store data on disk.
Files in Python are normally buffered (what you
write is temporarily stored in memory, so it can be sent in larger chunks, which is more effective). See the
buffering argument to
You can call the flush method before closing the file to write the data immediately.
Closing the file will also flush the buffer, so you’ll get the error produced by writing the data. The error you get depends on whatever device driver you’re controlling through the file.
If you don’t call
close(), the data should get written eventually, but any error will be silenced. Since you generally want to know when something goes wrong, I’d recommend using the
with statement with files – that way, the file is always properly closed when you’re done with it.