в блоке try-exception
в Python, как показано ниже, я хочу, чтобы печаталось мое справочное сообщение вместо собственного сообщения об ошибке Python.Возможно ли это?
def genpos(a):
''' Generate POSCAR :
Some error message'''
try:
tposcar = aio.read(os.path.join(root,"nPOSCAR"))
cell = (tposcar.get_cell())
cell[0][0] = a
cell[1][1] = math.sqrt(3)*float(a)
tposcar.set_cell(cell, scale_atoms=True)
aio.write("POSCAR", tposcar, direct=True)
except:
help(genpos)
sys.exit()
Итак, скажем, когда этот код вызывается без аргумента, я хочу получить «Generate POSCAR: Some error error» вместо Traceback python (последний вызов последним):
File "submit.py", line 41, in <module>
main()
File "submit.py", line 36, in __init__
ase_mod.genpos()
TypeError: genpos() missing 1 required positional argument: 'a'