PYTHON | Copying A File From An Unknown Destination
Hi my name is Oscar and I would like some help! So the scenario I have is that I am trying to write a python code that will copy itself and put that copy in another directory. I kn
Solution 1:
You could use pythons standard "os" library to make OS independent filepaths. Then you use the special "file" variable available inside any executed script to get the location of the executed script, to copy itself to some target location. Good luck!
Solution 2:
The filename of a python file is available using:
import sys
print(sys.argv[0])
You can use this filename to copy the same file elsewhere.
Solution 3:
I am super dumb it seems like, I did not know that you had to type the destination folder with to backslashes sometimes to actually make it a path. All solved, sorry for wasting everyone's time.
Post a Comment for "PYTHON | Copying A File From An Unknown Destination"