Python:使用异常参数时出现语法错误
我想使用异常的参数来显示代码中发生错误时的其他信息。 这是我的密码 ArgumentOfAnException.pyPython:使用异常参数时出现语法错误,python,exception,python-3.x,exception-handling,syntax-error,Python,Exception,Python 3.x,Exception Handling,Syntax Error,我想使用异常的参数来显示代码中发生错误时的其他信息。 这是我的密码 ArgumentOfAnException.py from pip._vendor.distlib.compat import raw_input def to_celsius(f): try: c = (f-32)*5/9; return c; except ValueError, Argument: print("The argumet doesn't con
from pip._vendor.distlib.compat import raw_input
def to_celsius(f):
try:
c = (f-32)*5/9;
return c;
except ValueError, Argument:
print("The argumet doesn't contain number\n", Argument);
return;
f = raw_input("Enter temperature in *F : ");
print("Temperature in Celsius : ", to_celsius(float(f)));
print("Thank you...");
在这里,当代码中出现错误时,我使用参数变量来显示附加信息,但在运行程序后,控制台输出中将显示语法错误,错误如下
File "F:\Document\Files\Coding\Java Eclipse\Python Project\First Project\src\Error\ArgumentOfAnException.py", line 7
except ValueError, Argument:
^
SyntaxError: invalid syntax
看起来您正在使用Python3.x 使用以下语法(使用
作为):
参考:是的,我使用python 3.4.3
except ValueError as Argument: