简体   繁体   中英

Create A File On Anyones Desktop Using Python

I am looking to create a log file on a users desktop, but since I do not know the username of the person using the computer I cant give my program the directory of where to place the file.

This is what works on PC since my username is mikur.

file = open("C:\\Users\\Mihkel\\Desktop\\KeyLog.txt", 'a')

I have tried using

file = open("C:\\Users\\Public\\Desktop\\KeyLog.txt", 'a')

but that gives me a no permissions error. Is there a solution to this?

尝试os.path.expanduser("~/Desktop")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM