I want to check whether user called function by passing any argument or not.
here is my function
def HEXtoRGB(hexlist):
rgblist = []
for i in range(len(hexlist)):
h = hexlist[i].lstrip('#')
rgb = tuple(int(h[i:i+2], 16) for i in (0, 2, 4))
rgblist.append(rgb)
return(rgblist)
print(HEXtoRGB())
HEXtoRGB()
takes hexlist
as a paramter. if user called HEXtoRGB()
function without argument then error message should print.
for that i tried error handling in python but its not working
def HEXtoRGB(hexlist):
try:
rgblist = []
for i in range(len(hexlist)):
h = hexlist[i].lstrip('#')
rgb = tuple(int(h[i:i+2], 16) for i in (0, 2, 4))
rgblist.append(rgb)
return(rgblist)
except:
print("Hex Color List Not Found")
print(HEXtoRGB())
above exception handling gives me same error
File "test.py", line 10, in <module>
print(HEXtoRGB())
TypeError: HEXtoRGB() missing 1 required positional argument: 'hexlist'
Is there any best way to handle missing argument error, In case user called function without argument