0

I'm a noobie to python. So I made this simple script which basically when run it takes 1 argument and then it copies the message associated with that argument to your clipboard. the code -

message =  {'available' : 'yeah, come to my office', 'busy' : 'nah, man busy right now', 'hate' : 'i dont like you anymore'}
    

import sys
import pyperclip

if len(sys.argv) < 2 :
    print('Usage:mclip[arg]')
    sys.exit()

keyphrase = 'busy'


if keyphrase in message.keys() :
    pyperclip.copy(message[keyphrase])
    print('{} copyied to clipboard'.format(message[keyphrase]))

else : 
    print('{} not in registered'.format(keyphrase))

Now, how do I run it from cmd?? I tried running it from the vs code powershell terminal which is is the same working directory as the file. But I keep getting this error -

python clipboard.py

C:\Users\Kakshipth\AppData\Local\Programs\Python\Python38-32\python.exe: can't open file 'clipboard.py': [Errno 2] No such file or directory

I get a similar error when I try python3 clipboard.py

Please help me out, also tell me how do you guys execute scripts? Like do you make a .bat file or just run the python file.

theknightD2
  • 321
  • 6
  • 17
default-303
  • 361
  • 1
  • 4
  • 15
  • 2
    "No such file or directory" is clear. Python can't find the file you want to execute. Make sure you have the file where you are on your path. – Austin Aug 07 '20 at 14:43
  • It says the file doesn't exist, and I believe it. If you saved it in a different folder, provide the path to that folder, or move it to the folder where you want it. For example, `python c:\users\you\clipboard.py busy` – tripleee Aug 07 '20 at 14:43
  • @triplee @Austin yes, i cd ed into the directory and then typed 'python clipboard.py busy` and it worked. but like changing directory everytime and executing looks tedious to me. Is this how you guys execute scripts??Thanks – default-303 Aug 07 '20 at 14:50
  • well i dont know what a `wrapper` file is. Ill look it up. thanks tho – default-303 Aug 07 '20 at 14:56
  • See also https://stackoverflow.com/questions/11472843/set-up-python-on-windows-to-not-type-python-in-cmd – tripleee Aug 07 '20 at 14:58

1 Answers1

0

You need to open the terminal/command line inside the folder that contains your python file.

If it still doesnt work try:

python ./clipboard.py
  • yes, i had to change my working dir and then entered `python clipboard.py` followed by argument. And it works now. But changing directory everytime and then executing looks like a tedious task to me. Is this how you run scripts?? – default-303 Aug 07 '20 at 14:52
  • Yes that is how you run scripts. Otherwise Windows won't know what file you want to execute. You could use a batch file that contains the command and double click that to run the command if that works for you and your arguments wont change for testing. – Niklas Ziermann Aug 07 '20 at 14:53
  • i mean changing the directory everytime part. Is there no other way around it ?? – default-303 Aug 07 '20 at 14:55
  • there is a shortcut to open the comand prompt inside your active folder: type cmd inside your file explorer (where your current dir is shown) https://youtu.be/bgSSJQolR0E – Niklas Ziermann Aug 07 '20 at 15:59