Getting face normals from python?

I’m looking for to output per face normals for Blender models but from
looking at the Python docs Blender doesn’t seem to have the normal coordinates
stored in the faces…??
Am I missing something here, where exactly is Blender getting
the normals for flat shading if they’re not stored in the faces. It’s hardly using
a per frame calculation based on vertex normals… or is it?

well, it isn’t based on vertex normals
but they are recalculated at least every frame.

there have been other people asking how to get them, look for their threads.

Ok z3r0 d maybe you can anwser this question that has mystified me for a while. How can a vertex have a normal. I mean its just a point in space. If I remember from my high school geometry class, a normal is the vector that is perpendicular to a plane. Well I vertex is just a point how can it have a normal??

Normal vectors are (re)calculated every time they are needed.
But it is not so difficult to calculate the normal of a face if you know the coordinates of the face.

# vector substration
def vecsub(a, b):
    return [a[0] - b[0], a[1] - b[1], a[2] - b[2]]

# vector crossproduct
def veccross(x, y):
    v = [0, 0, 0]
    v[0] = x[1]*y[2] - x[2]*y[1]
    v[1] = x[2]*y[0] - x[0]*y[2]
    v[2] = x[0]*y[1] - x[1]*y[0]
    return v

# calculate normal from 3 verts
def Normal(v0, v1, v2):
    return veccross(vecsub(v0, v1),vecsub(v0, v2))

That goes good for triangular faces, but if the face is not coplanar (could happen with quads), use the following (found in the blender sourcecode):

# calculate normal from 4 verts
# found in the blender sources in arithb.c 
# (bl-blender\blender\source\blender\blenlib\intern\arithb.c)
def Normal4(v0, v1, v2, v3):
    return veccross(vecsub(v0, v2),vecsub(v1, v3))

Thank you very much for this tuinbels. I’m working (when I have free time) on a Select/Paint-Gradient script,
that will either:
allow me to select faces with a normal facing in a particular direction (with some room for error);
or paint it, either with a material, or vertex painting.
The plan is that I can add e.g. snow materials to the secondary valleys of a mountain ridge.

I spent quite some time working out some truely horrendous code to calculate the weighted average of a face normal from the vector normals. Now I just have to work out how to seperate valleys, saddle-points and peaks. sighs