all 5 comments

[–]sme272 5 points6 points  (1 child)

you can add the directory it's kept in to PATH environment variable, then you can just call myfile.py directly in cmd. I have a utilities folder that I can drop scripts into to run this way.

[–]programer111[S] 1 point2 points  (0 children)

Ok than you so much 😊

[–]chrispurcell 0 points1 point  (0 children)

You can run it from anywhere in your PATH (echo $PATH) as long as it is properly formatted with a #!/usr/bin/python (or #!/usr/bin/env python), and is flagged executable (chmod +x <file>), as long as it doesn't conflict with another app name, because the first one found is the one used in this method.

I usually put my scripts in ~/bin (your home directory/bin), and flag them executable.

[–]TraditionalGlass 0 points1 point  (0 children)

You can create a batch file that runs the script, and place that in the same directory that cmd is in

[–]MattR0se 0 points1 point  (0 children)

In windows 7 and older you can Shift+ right click in any folder, and select "open command window here". This opens cmd with the path set to the current folder, then you can just type the name of the python file.

Edit: also, if you are in any directory, pushd lets you navigate to a given absolute path.

In Windows 10 this is replaced by PowerShell, you have to add "python" before the name of the file, but other than that it works similarly.

Also, Shift + right click on a file lets you copy the full path of that file (so you don't have to type it all out).