Blender 2.8 : python code to switch shading mode (between wireframe and solid mode) If i switch between solid and wireframe mode, i can see in the info window that these commands are invoked :

bpy.data.screens["Layout"].shading.type = 'WIREFRAME'
bpy.data.screens["Layout"].shading.type = 'SOLID'


Now i want to execute this command using python console. So i cut and paste the codes into python console but i got this error : 

&gt;&gt;&gt; bpy.data.screens["Layout"].shading.type = 'WIREFRAME'
Traceback (most recent call last):
  File "&lt;blender_console&gt;", line 1, in &lt;module&gt;
AttributeError: 'Screen' object has no attribute 'shading'

&gt;&gt;&gt; bpy.data.screens["Layout"].shading.type = 'SOLID'
Traceback (most recent call last):
  File "&lt;blender_console&gt;", line 1, in &lt;module&gt;
AttributeError: 'Screen' object has no attribute 'shading'


Does anyone know why ? and what the correct script should i use in python console ?

Thanks
As to why the script generates an error:
When directly clicking on a button on the screen Blender understands the context of which workspace (tabs across the top of the screen) and area (window within the screen) you are accessing.
Your code fails to identify where exactly you want to apply the change.

import bpy

my_areas = bpy.context.workspace.screens[0].areas
my_shading = 'WIREFRAME'  # 'WIREFRAME' 'SOLID' 'MATERIAL' 'RENDERED'


for area in my_areas:
    for space in area.spaces:
        if space.type == 'VIEW_3D':
            space.shading.type = my_shading