-1

Hello there I have this code:

login=os.getlogin()
if not os.path.exist("C:\Users\login\Documents")

As you can see I have a login variable that gets the user of the computer but I am struggling to use it in the ''if not os.path.exist'' statement, The output I want is for python to get the username of the user and use it in a directory.

Thanks in advance!

Increasingly Idiotic
  • 5,700
  • 5
  • 35
  • 73
Mattz Manz
  • 43
  • 2
  • 7

1 Answers1

0

You can use string formatting:

if not os.path.exists("C:\Users\{0}\Documents".format(login)):

Or you can build up the string by yourself:

if not os.path.exists("C:\Users\\" + login + "\Documents"):

or if by using join:

if not os.path.exists(os.path.join("C:/", "Users", login, "Documents"):

As already indicated by comments, you should also have a look on this question. This shows you how to properly get the login name.

tangoal
  • 724
  • 1
  • 9
  • 28