How to know which side of a face is being rendered?
You need 2 vectors for calculating this:


A = the face normal
B = a vector pointing from camera to the face center (face.calc_center_median(), = point of face normal origin)


You get both from the python API from mesh or bmesh data and from Camera object location.

Then you calculate a Dot product between these 2:

from mathutils import Vector

C = A.dot(B)



if the dot product is negative, the vectors point towards each other (face is oriented towards the camera)
if the dot product is 0, the vectors are orthogonal and the face is not visible
if the dot product is positive, the vectors point in the same direction and you see the backface from camera


You can see how dot product works here: www.falstad.com/dotproduct/

Alternatively to solve this inside shaders you can use the Geometry node. In Cycles the socket is named Backfacing, in Blender Internal the socket is named Front/Back. You can have a material that chooses from 2 materials based on this mix factor. This approach will dynamically switch between materials even if the camera is animated, this does not happen if you assign materials with script and then during animation the camera angles change.