0

The temp directory in win 7 is %userprofile%\AppData\Local\Temp and I'd like to add it to a python script as a variable to be used to create a text file there.

However, because of the % at the beginning, it makes python unable to identify it. I tried to add double %%, but that didn't work as well.

What should I do?

NotANormalNerd
  • 415
  • 3
  • 14
AhmedWas
  • 1,205
  • 3
  • 23
  • 38

1 Answers1

2

You should use the tempfile module instead:

import tempfile
my_temp = tempfile.NamedTemporaryFile()

This is the platform-independent way to have a temporary file.

wim
  • 338,267
  • 99
  • 616
  • 750