'Context' object has no attribute 'view_layer' in Python Script I'd like to run the script here 
but hit an error on the 2nd line: 

view_layer = bpy.context.view_layer
Traceback (most recent call last):
  File "/usr/lib/python3.6/code.py", line 91, in runcode
    exec(code, self.locals)
  File "&lt;blender_console&gt;", line 1, in &lt;module&gt;
AttributeError: 'Context' object has no attribute 'view_layer'


Autcompleting the bpy.context object does show there's no view_layer property...maybe the docs are outdated?
The manual page you've linked is for Blender 2.81 and is up-to-date. If you're using an older version of Blender you'll have to consult the matching version of the manual. The documentation of bpy.types.Object in Blender 2.79 can be found here.