I have a python script that accepts file names as arguments and performs operation on those files. Currently the script is in the same directory as the files it operates on. But I want to be able to run my python script from anywhere in the operating system. When I give the file name as argument to the script, it should know exactly which directory to look for regardless of where the python script is running in the system. How can I achieve this in python?
Here is the relevant portion of the script. Can I just hard code the path? The type_mapping_file will be the filename passed into the script as an argument.
data = None
with open (type_mapping_file, "r") as myfile:
data=myfile.read()
if(data is not None):
request_params = {'type': type_name, 'index': index_name}
send_http_request("/index/type/create", request_params, base_url, post_body=data)
Thank you in advance.