How to set the value of a MeshPolygonStringProperty to a string? I am trying to set a string attribute per polygon on a mesh. To create the property, I use:
a = m.polygon_layers_string.new(name='object')
x = a.data[0]

but when I try to set the data:
x.value = 'blah'
Traceback (most recent call last):
  File &quot;&lt;blender_console&gt;&quot;, line 1, in &lt;module&gt;
TypeError: bpy_struct: item.attr = val: MeshPolygonStringProperty.value expected a bytes type, not str

When I inspect the types:
type(x)
&lt;class 'bpy.types.MeshPolygonStringProperty'&gt;

and
type(x.value)
&lt;class 'bytes'&gt;

But the documentation here mentions the type of x.value should be a string, or am I misreading?
What is the correct way to store a string per polygon?
Use the bmesh API
Suggest using bmesh for polygon string layers.
import bpy
import bmesh   

context = bpy.context
ob = context.object
me = ob.data

bm = bmesh.new()
bm.from_mesh(me)
str_layer = bm.faces.layers.string.new(&quot;Foo&quot;)

for f in bm.faces:
    f[str_layer] = bytes(f'Face {f.index}', 'utf-8')  # b`foo`
    
bm.to_mesh(me)
bm.clear()

for s in me.polygon_layers_string:
    print(f&quot; Layer {s.name}&quot;)
    for p in s.data:
        print(p.value.decode())