def name_to_uid(name):
 try:
  uid = int(name)
 except ValueError:
  try:
   pwdrec = pwd.getpwnam(name)
  except KeyError:
   raise ValueError(('Invalid user name %s' % name))
  uid = pwdrec[2]
 else:
  try:
   pwd.getpwuid(uid)
  except KeyError:
   raise ValueError(('Invalid user id %s' % name))
 return uid

def name_to_uid ( name ) : try : uid = int ( name ) except ValueError : try : pwdrec = pwd . getpwnam ( name ) except KeyError : raise ValueError ( ( 'Invalid user name %s' % name ) ) uid = pwdrec [ 2 ] else : try : pwd . getpwuid ( uid ) except KeyError : raise ValueError ( ( 'Invalid user id %s' % name ) ) return uid
find a user id from a string containing a user name or id .