Gurnoor
Gurnoor

Reputation: 133

How to get the name of a python script

Ok so I have a python script that will move its self to the desktop when its run, but I want it to be able to move itself no matter what its name is. My current code only moves it when it is called a specific thing.

My current code is

shutil.move("moveMe.py", "C:/Users/" + user + "/desktop/")

I've experimented with __ name__ because from what its name implies it would be the name of the file but I'm not 100% sure how to use it yet as I'm quite new to python

Upvotes: 0

Views: 72

Answers (1)

Patrick J. Holt
Patrick J. Holt

Reputation: 706

Try to use __file__ or import sys and use sys.argv[0]

Upvotes: 2

Related Questions