问题
I'm trying to write a program on JupyterLab (Ipython) which takes Command Line arguments as its input.
#! python3
# pw.py - An insecure password locker program.
PASSWORDS = {'email': 'F7minlBDDuvMJuxESSKHFhTxFtjVB6',
'blog': 'VmALvQyKAxiVH5G8v01if1MLZF3sdt',
'luggage': '12345'}
import sys,pyperclip
if len(sys.argv) < 2:
print('Usage: python pw.py [account] - copy account password')
sys.exit()
account = sys.argv[1] # first command line arg is the account name
if account in PASSWORDS:
pyperclip.copy(PASSWORDS[account])
print('Password for ' + account + ' copied to clipboard.')
else:
print('There is no account named ' + account)
input('press ENTER to exit')
I am working on JupyterLabs, and when I run it there, for some reason I get this output:
There is no account named -f
Press Enter to Exit
''
I don't understand why am I getting this '-f' value.
If I try to print out my sys.argv arguments with the following code:
import sys
print ("This is the name of the script: ", sys.argv[0])
print ("Number of arguments: ", len(sys.argv))
print ("The arguments are: " , str(sys.argv))
The output is:
This is the name of the script: C:\Anaconda\lib\site-packages\ipykernel_launcher.py
Number of arguments: 3
The arguments are: ['C:\\Anaconda\\lib\\site-packages\\ipykernel_launcher.py', '-f', 'C:\\Users\\Yakov\\AppData\\Roaming\\jupyter\\runtime\\kernel-7a28a8cc-9164-4299-a49c-9a6739872b59.json']
Could somebody explain what to do to get rid of this '-f'?
When I run the program from the Command Prompt, everything works fine:
来源:https://stackoverflow.com/questions/62656582/jupyterlab-sys-argv1-is-f