temp files/directories with custom names?
问题 How to create a temporary files/directories with user defined names in python. I am aware of tempfile . However I couldn't see any function with filename as argument. Note: I need this for unit testing the glob(file name pattern matching) functionality on a temporary directory containing temporary files rather than using the actual file system. 回答1: You can use open() with whatever file name you need. e.g. open(name, 'w') Open Or import os import tempfile print 'Building a file name yourself: