Python context error NameError: name 'context' is not defined
What you're looking for is bpy.context, so the first line should be:

obj = bpy.context.active_object


It refers to the bpy module being imported in the first line.

You can also use this at the beginning of your scripts:

import bpy
from bpy import context


The entire script should look like this:

import bpy
import bmesh

ob = bpy.context.object
me = ob.data
bm = bmesh.from_edit_mesh(me)

uv_layer = bm.loops.layers.uv.verify()
bm.faces.layers.tex.verify()

for f in bm.faces:
    for l in f.loops:
        luv = l[uv_layer]
        if luv.select:
            luv.uv = l.vert.co.xy

bmesh.update_edit_mesh(me)