Fixed the basename file path bug and tested it to work regardless of whether called through python or shell.