I have the following method in Python.
def get_rum_data(file_path, query):
if file_path is not None and query is not None:
command = FETCH_RUM_COMMAND_DATA % (constants.RUM_JAR_PATH,
constants.RUM_SERVER, file_path,
query)
print command
execute_command(command).communicate()
Now inside get_rum_data I need to create the file if it does not exists, if it exists I need to append the data. How to do that in python.
I tried, open(file_path, 'w') , which gave me an exception.
Traceback (most recent call last):
File "utils.py", line 180, in <module>
get_rum_data('/User/rokumar/Desktop/sample.csv', '\'show tables\'')
File "utils.py", line 173, in get_rum_data
open(file_path, 'w')
IOError: [Errno 2] No such file or directory: '/User/rokumar/Desktop/sample.csv'
I though open would create file in write mode.
open('/path/to/file', 'w'). Does it fail?os.pathmodule.