How to set UV coordinates for a mesh in Blender 2.8x with script?
That code worked in 2.79?

Please when posting code in future make sure you leave in all relevant lines. eg in question what is o, i, u, v

Very little difference between this answer and the following, real toss up between answering and closing as duplicate, which I'll leave for others. Quicker to answer and hence confirm in 2.82.

Get/Set coordinates for UV vertices using Python

Add uv_layer to mesh, add uv-coords, with python

Add a new layer (same). Notice if a new layer is added, but there is an existing layer, it will not be index 0. Will be the last, or easier keep the reference returned.

&gt;&gt;&gt; me.uv_layers.new(
new()
UVLoopLayers.new(name="UVMap", do_init=True)
Add a UV map layer to Mesh


get or set the active layer, it can be None a gotcha in answers to links above.

&gt;&gt;&gt; me.uv_layers.active
bpy.data.meshes['Cube'].uv_layers["UVMap"]

&gt;&gt;&gt; me.uv_layers.active = None


Silly example adds random UV (a scribbly mess) to each UV



import bpy
from random import random
context = bpy.context

ob = context.object
me = ob.data
uvlayer = me.uv_layers.new() # default naem and do_init

me.uv_layers.active = uvlayer

for face in me.polygons:
    for vert_idx, loop_idx in zip(face.vertices, face.loop_indices):
        uvlayer.data[loop_idx].uv = (random(), random()) # ie UV coord for each face with vert  me.vertices[vert_idx]