【发布时间】:2015-02-07 04:32:20
【问题描述】:
不知道为什么我似乎得到了这个语法错误,当我在 pycharm 中运行代码时它工作得很好
我有:
import sys
import os.path
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
from DiceRolls import RandomDiceRoll
num = [int(n) for n in input("Enter Numbers: ").split(",")]
for n in num:
print(RandomDiceRoll.diceRoll(n))
RandomDiceRoll 这样做:
import sys
import random
def diceRoll(n1):
w = random.randint(1,n1)
return w
现在,当我在 pycharm 中运行它时,它运行良好,并打印出我想要的结果。
但是,如果我使用 python scriptName.py 从终端运行它,我会得到:
Enter Numbers: 4 0 0
Traceback (most recent call last):
File "userEnter.py", line 9, in <module>
num = [int(n) for n in input("Enter Numbers: ").split(",")]
File "<string>", line 1
4 0 0
^
我觉得我正在做一些我应该接受的事情,但我似乎找不到它,任何帮助都会很棒!
【问题讨论】:
-
我猜终端使用的是 py2 ...尝试使用 Py3 运行(在 Linux 中 ---
python3 scriptName.py在 OsX 中不知道) -
是的,就是这样,之后它是一个字符串文字,因为','在我不想要的拆分中
标签: python list python-3.x terminal