def package_name(pkg_or_module):
 if ((pkg_or_module is None) or (pkg_or_module.__name__ == '__main__')):
  return '__main__'
 pkg_name = pkg_or_module.__name__
 pkg_filename = getattr(pkg_or_module, '__file__', None)
 if (pkg_filename is None):
  return pkg_name
 splitted = os.path.split(pkg_filename)
 if (splitted[(-1)] in init_names):
  return pkg_name
 return pkg_name.rsplit('.', 1)[0]

def package_name ( pkg_or_module ) : if ( ( pkg_or_module is None ) or ( pkg_or_module . __name__ == '__main__' ) ) : return '__main__' pkg_name = pkg_or_module . __name__ pkg_filename = getattr ( pkg_or_module , '__file__' , None ) if ( pkg_filename is None ) : return pkg_name splitted = os . path . split ( pkg_filename ) if ( splitted [ ( - 1 ) ] in init_names ) : return pkg_name return pkg_name . rsplit ( '.' , 1 ) [ 0 ]
if this function is passed a module .