def name_to_gid(name):
 try:
  gid = int(name)
 except ValueError:
  try:
   grprec = grp.getgrnam(name)
  except KeyError:
   raise ValueError(('Invalid group name %s' % name))
  gid = grprec[2]
 else:
  try:
   grp.getgrgid(gid)
  except KeyError:
   raise ValueError(('Invalid group id %s' % name))
 return gid

def name_to_gid ( name ) : try : gid = int ( name ) except ValueError : try : grprec = grp . getgrnam ( name ) except KeyError : raise ValueError ( ( 'Invalid group name %s' % name ) ) gid = grprec [ 2 ] else : try : grp . getgrgid ( gid ) except KeyError : raise ValueError ( ( 'Invalid group id %s' % name ) ) return gid
find a group id from a string containing a group name or id .