List all view layers in all scenes using Python

Hi,
I’m trying to list all layers in all scenes using python. I tried this below, but it’s not working. Could you help me please ?

for scene in bpy.data.scenes:
    print('scene : %s'%scene.name)
    for layer in bpy.data.scenes[str(scene)].view_layers:
         print('___ %s'%layer.name)

like this its working.
You called the scene object instead of its name. “import bpy” was forgotton too or you just didnt post this part.

import bpy

for scene in bpy.data.scenes:
    print('scene : %s'%scene.name)
    for layer in bpy.data.scenes[str(scene.name)].view_layers:
         print('___ %s'%layer.name)

But actually its more simple like this

import bpy

for scene in bpy.data.scenes:
    print('scene : %s'%scene.name)
    for view_layer in scene.view_layers:
         print('___ %s'%view_layer.name)

Thanks ! for your answer ! I found this and it’s working :

for scene in bpy.data.scenes:
    print('scene : %s'%scene.name)
    for layer in scene.view_layers:
         print('___ %s'%layer.name)

Now I’m trying to exclude all layers except the current layer in current scene. I tried this below, but it dont exclude the layer in current scene.

import bpy

currentLayer = bpy.context.view_layer
currentScene = bpy.context.scene
print('CURRENT LAYER : '+currentLayer.name+' in scene '+currentScene.name)

for scene in bpy.data.scenes:
    print('\n scene : %s'%scene.name)
    for layer in scene.view_layers:
        
        if layer != currentLayer and scene != currentScene:
            print('___ %s'%layer.name+' -> EXCLUDED')
            #layer.use = False
        else:
            print('___ %s'%layer.name)

This works, but it probably not the smartest solution :

import bpy

currentLayer = bpy.context.view_layer
currentScene = bpy.context.scene
print('CURRENT LAYER : '+currentLayer.name+' in scene '+currentScene.name)

for scene in bpy.data.scenes:
    print('\nSCENE : %s'%scene.name)
    for layer in scene.view_layers:
        
        if scene != currentScene:
            print('___ %s'%layer.name+' -> EXCLUDED')
            #layer.use = False
        else:
            if layer != currentLayer:
                print('___ %s'%layer.name+' -> EXCLUDED')
                #layer.use = False
            else:
                print('___ %s'%layer.name)