JupyterLab sys.argv[1] is '-f'

本秂侑毒 提交于 2020-08-10 18:55:19

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!