Temporary file with specific file extension in Python 3

前端 未结 2 1401
盖世英雄少女心
盖世英雄少女心 2021-01-07 17:04

I am writing some unit tests for a piece of code that takes a path and attempts to load the file if it has a known extension, then does more careful checking.

In the

相关标签:
2条回答
  • 2021-01-07 17:32

    This doesn't work for you?

    In [2]: tempfile.NamedTemporaryFile(suffix='.tif').name
    Out[2]: '/var/folders/gq/swc6jtld5853skyq_xc2lpc40000gn/T/tmplrtwvxg7.tif'
    
    0 讨论(0)
  • 2021-01-07 17:41

    did you try?

    fd, path =tempfile.mkstemp(suffix = '.tif')
    print(path)
    
    0 讨论(0)
提交回复
热议问题