简体   繁体   中英

How do I run python scripts from terminal?

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.

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

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM