0

I´m trying to write a file into the %temp%-Folder, but the username of every User is different.

Does Python have a function or some kind like that to join the folder? I tried it like this, but I get an Syntax Error, because Python can't decode it:

tmppath = "C:\Users\ %s \AppData\Local\Temp" %( os.getlogin() )

thx for help :)

Edit: The Error, in case it helps:

SyntaxError: (Unicode Error) 'unicodeescape' codec can't decode bytes in     
position 2-3: truncated \UXXXXXXXX escape
freedome97
  • 167
  • 3
  • 15

1 Answers1

1

You need to replace each \ with \\. Also, you should use str.format() instead of %s%:

import os
tmppath = "C:\\$SB52EF.tmpUsers\\{}\\AppData\\Local\\Temp".format(os.getlogin())

You might be interested in this question.

Community
  • 1
  • 1
Farhan.K
  • 3,425
  • 2
  • 15
  • 26