pythonwindowsmacosfilepath

How do I start the file path from the users directory?


I am trying to create a script in python that creates a text file on the user's desktop. I need this to work on both Mac and Windows but it doesn't need to be in the same script as I have one script for mac and one for Windows. I can't seem to find a way for python to create a file with the path beginning at the user's directory (like ~/ for Linux) as I don't know the user's username. Thanks for any help!


Solution

  • You can use the same ~ across different platforms with os.path.expanduser.