Strange shading after running python script
The "lines" are where you have duplicate vertices where you have re-joined your mesh. You can see a slight variation if you enable vertex normal display.



The solution is to remove doubles in python or manually with W->Remove Doubles.

bmesh.ops.remove_doubles(bm, verts=bm.verts, dist=0.02)