filepath = r"E:/output.csv"
import bpy
from bpy import data as D
with open(filepath, 'w') as f:
for ob in D.objects:
# if ob.type != 'MESH': continue
names = [s.material.name for s in ob.material_slots if s.material]
print(ob.name, *names, sep=",", file=f)
If you really want to save meshes (which is not the same as objects) materials:
filepath = r"E:/output.csv"
import bpy
from bpy import data as D
with open(filepath, 'w') as f:
for me in D.meshes:
names = [m.name for m in me.materials if m]
print(me.name, *names, sep=",", file=f)
Edit: output also names of the textures:
filepath = r"E:/output.csv"
import bpy
from bpy import data as D
with open(filepath, 'w') as f:
for ob in D.objects:
# if ob.type != 'MESH': continue
materials = [s.material for s in ob.material_slots if s.material]
names = [
(m.name, m.node_tree.nodes['Image Texture'].image.name)
for m in materials if m.node_tree
]
names = sum(names, ()) # flatten [(1, 2), (3, 4)] -> (1, 2, 3, 4)
print(ob.name, *names, sep=",", file=f)