In addition to all the answers, you can use the inspect library
>>> def f(a,b,c):
... print inspect.getargspec(f).args
...
>>> f(1,2,3)
['a', 'b', 'c']
>>> def f(a,e,d,h):
... print inspect.getargspec(f).args
...
>>> f(1,2,3,4)
['a', 'e', 'd', 'h']
Edit:
without using the name of the function:
>>> def f(a,e,d,h):
... print inspect.getargvalues(inspect.currentframe()).args
...
>>> f(1,2,3,4)
['a', 'e', 'd', 'h']
The function may looks like:
def validate_user(surname, username, passwd, password, errors):
errors = []
for arg in inspect.getargspec(validate_user).args[:-1]:
value = eval(arg)
if not value:
errors.append("{0} may not be empty, please enter a {1}.".format(arg.capitalize(), arg))
elif len(value) > 20:
errors.append("Please shorten {0} to atmost 20 characters (|{1}|>20)".format(arg,value))
return errors
>>> validate_user("foo","","mysuperlongpasswordwhichissecure","",[])
['Username may not be empty, please enter a username.', 'Please shorten passwd to atmost 20 characters (|mysuperlongpasswordwhichissecure|>20)', 'Password may not be empty, please enter a password.']