I made this script to copy this file to any user's Documents folder:
import getpass
import os
user = getpass.getuser() #gets username
file = "try.py" #file to copy
new_file = "C:\\Users\\", user,"\\Documents\\try.py" #folder in which the file shoud copy
os.rename(file, new_file) #copy the file
The problem is, when I try to run it, IDLE show this error:
I don't really understand what it means. Please note that I am a beginner in Python.
new_file is not a concatenated string but a tuple.
Try using this for concatenation of strings
new_file = "C:\\Users\\" + user + "\\Documents\\try.py"
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.