2

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')
Amrmsmb
  • 1
  • 27
  • 104
  • 226
  • 1
    Exactly the same question as [Get path from open file in Python - Stack Overflow](https://stackoverflow.com/questions/9542435/get-path-from-open-file-in-python) ... except for the failed attempt. (← although because you don't explain why you think like that there's nothing to explain about it) – user202729 Oct 01 '21 at 05:51

0 Answers0