I need to pass a file path name to a module. How do I build the file path from a directory name, base filename, and a file format string?
The directory may or may not exist at the time of call.
For example:
dir_name="/home/me/dev/my_reports"
base_filename="daily_report"
format="pdf"
I need to create a string '/home/me/dev/my_reports/daily_report.pdf'
Concatenating the pieces manually doesn’t seem to be a good way. I tried os.path.join
:
join(dir_name,base_filename,format)
but it gives
/home/me/dev/my_reports/daily_report/pdf