# remove all namespaces in the scene
namespaces = maya.cmds.namespaceInfo(listOnlyNamespaces=True, recurse=True)
namespaces.remove("UI")
namespaces.remove("shared")
namespaces.sort(reverse=True)
for name_space in namespaces:
maya.cmds.namespace(moveNamespace=[name_space, ":"], force=True)
maya.cmds.namespace(removeNamespace=name_space)