How do I set the file path to the current user?
问题 Right now for a directory path, I have: os.chdir(r'C:\users\Ryan\AppData\Local\Google\Chrome\Application') How do I make it so that instead of "Ryan" it uses the username of the person using the script? 回答1: Take a look at expanduser of os.path: os.path.expanduser(path) On Unix and Windows, return the argument with an initial component of ~ or ~user replaced by that user‘s home directory. [..] On Windows, HOME and USERPROFILE will be used if set, otherwise a combination of HOMEPATH and