NameError and ValueError in Python -
why python shell throwing nameerror windows console valueerror?
def printargs(*arg): list = ['1','2'] in arg: try: print(list[int(i)]) except valueerror: print('please enter integer value') except nameerror: print('name error') if __name__ == '__main__': printargs(*sys.argv[1:])
providing following arguments windows console gives output:
here how call code in windows console:
c:\>c:\python34\python c:\users\user\documents\pytest\test.py 0 1 please enter integer value
providing following arguments python shell not display cusom error nameerror mentioned in code above, mentions following error:
printargs(0,a) traceback (most recent call last): file "<pyshell#0>", line 1, in <module> printargs(0,a) nameerror: name 'a' not defined
in code example you've provided define list i, iterate on collection called list never initiated, , assign values in list i, dropping original value. guess provided part of code, please provide minimum working example.
if try reproduce problem, type error, iterating on list not initialized.
Comments
Post a Comment