Just want to set viewport to wireframe from script Not sure how best to do this...

I have a very simple question. When I click on the solid view icon in the window I see the console shows:

bpy.context.space_data.shading.type = 'WIREFRAME'


But when I add that to the Text Script window:

import bpy
bpy.context.space_data.shading.type = 'WIREFRAME'


It of course doesn’t run because it doesn’t have the proper context.
I also tried:

import bpy

prev_type = bpy.context.area.type
bpy.context.area.type = 'VIEW_3D'
bpy.context.space_data.shading.type = 'SOLID'
bpy.context.area.type = prev_type


which doesn’t throw an error, but doesn’t work either. I know it must be something simple, but how to fix this? Thanks!
Screen is divided into areas.

An areas active space, matches area type.

2nd script will set the 3d view in that space to solid shading, change text editor to 3d view to confirm. 

To set 3dviews  in context screen, find them first  

spaces3d = [a.spaces.active for a in context.screen.areas if a.type == 'VIEW_3D']
for s in spaces3d: 
    s.shading.type = 'SOLID'


If there are more than one view 3d open, you may wish to only set the largest area, can sort the list by area area (a.width * a.height)