I am trying to create and overwrite a file in file system. The below code working with local filesystem and NFS as well.
But not working with HDFS NFS gateway.
open_file = open("/hdfs_nfs/hdfs_Data/sampledata/testWrite.txt", 'wb+') open_file.write("This is just a sample data") open_file.close()
The file "testWrite.txt" is getting created on HDFS mount point when i run above code for first time. But it is not working when I run the code from 2nd time onwards, with or with out changing the content.
I am getting below error.
IOError: [Errno 22] invalid mode ('wb+') or filename: '/hdfs_nfs/hdfs_Data/sampledata/testWrite.txt'
According to the official documentation "file append is supported but random write is not supported". However, you very much can remove the file if it already exists and create a new one:
import os path = '/hdfs_nfs/hdfs_Data/sampledata/testWrite.txt' try: os.remove(path) except OSError: pass with open(path, 'wb+') as open_file: open_file.write("This is just a sample data")