UV-coordinates via Python do not match UV-coordinates in editor!?

I want to readout the the UV-coordinates for a given object. The first thing I notice is, that in the UV-editor the coordinates are given in pixel-space while via Python they are given as percentage. Ok, I think I can deal with it.

However, the coordinates do not seem to resemble what I see in the editor. Here is an example:


I created a plane, subdivded it, unwraped it and everything is fine. Now, as an illustration of the problem, I want to depict the uv-coordinates in 3D. I do this with the following code:

import bpy


object = bpy.data.objects['Plane.001']


world_d = []
uv_d = []


for i in range(0, len(object.data.vertices)):
    object.data.vertices[i].co[0] = object.data.uv_layers.active.data[i].uv[0]
    object.data.vertices[i].co[1] = object.data.uv_layers.active.data[i].uv[1]
    object.data.vertices[i].co[2] = 0   

To my surprise, the mesh looks like this:


Has anybody an idea what went wrong or how to access the uv-coordinates that I can see in the UV-editor?

after hours of trying to solve this problem on my own I decided to post this problem here.

five minutes after posting this problem I found the solution. uv-coordinates are stored polygon-wise. the right code to do it is:

import bpy

object = bpy.data.objects['Plane.001']

for i in range(0, len(object.data.polygons)):
    uvs = [object.data.uv_layers.active.data[li] for li in object.data.polygons[i].loop_indices]    
    
    for vi in range(0, len(object.data.polygons[i].vertices)):
        object.data.vertices[object.data.polygons[i].vertices[vi]].co[0] = uvs[vi].uv[0]
        object.data.vertices[object.data.polygons[i].vertices[vi]].co[1] = uvs[vi].uv[1]
        object.data.vertices[object.data.polygons[i].vertices[vi]].co[2] = 0

thank you forum for your aura

also see this:

Exporting UV coordinates

thx for the link