How to get the path given file object

Viewed 37

i have the below posted code, it open a file and write binary contents to it. if the file already exists, the file will be returned. my question is, given the object open(pathToFile,'r') or outfile, how can i get the path out of them i tried the following

os.path(tiffFile).name

but i receive an error

TypeError: 'module' object is not callable

code:

def writeBinaryContentsToFile(self,pathToFile, contents):
    # pathToOutputDir = os.path.join(os.getcwd(), pathToFile)
    logger.debug("pathToFile:{0}".format(pathToFile))
    if not path.exists(pathToFile):
        logger.debug("file will be created")
        with open(pathToFile,"wb") as outfile:
            outfile.write(contents)
        return outfile
    else:
        logger.debug("file already exists")
        return open(pathToFile,'r')
0 Answers
Related