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
3
  • Replace single backslashes by two. Commented Apr 7, 2016 at 14:54
  • Please don't do that when you have dedicated tempfile module to help you deal with cross-platform support. Commented Apr 7, 2016 at 15:00
  • Thx for the fast help, it works. It rly was just the confusion with the backslashes ._. Commented Apr 7, 2016 at 15:03

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.