相关疑难解决方法(0)

在Jupyter Notebook中运行Python脚本,并传递参数

我有一个从Jupyter Notebook运行的简单Python脚本。但是,我传递给它的参数似乎被忽略了,这导致异常:

two_digits.py

import sys
input = sys.stdin.read()
tokens = input.split()
a = int(tokens[0])
b = int(tokens[1])
print(a + b)

%run two_digits 3 5

ndexError                                Traceback (most recent call last)
D:\Mint_ns\two_digits.py in <module>()
      5 tokens = input.split()
      6 
----> 7 a = int(tokens[0])
      8 
      9 b = int(tokens[1])

IndexError: list index out of range
Run Code Online (Sandbox Code Playgroud)

python jupyter jupyter-notebook

4
推荐指数
2
解决办法
1万
查看次数

标签 统计

jupyter ×1

jupyter-notebook ×1

python ×1