perlquestion
mpersico
I am working with [mod://Inline::Python]. In order to pass string data into Python, I am calling [mod://Data::Structure::Util]::utf8_on() on all the data I am passing into any function call that is Python. It seems to work well except for the hash keys. Python complains: "TypeError: keys must be str, int, float, bool or None, not bytes at line 39". Turns out that in that module <A HREF="https://metacpan.org/release/ANDYA/Data-Structure-Util-0.16/source/Util.xs#L65">(sample here)</A>, only the values are set to utf8, not the keys.
<p>
Is there a way to set the keys to utf8 in XS? I was hoping for a HeKEY macro, but doing some poking around, I only see keys being retrieved, not set.
<p>
Failing that, would a simple:
<code>
my %newhash;
for (keys %oldhash) {
$newhash{utf8_on($_)} = $newhash{$_};
}
call_pyfunc(\%newhash);
</code>
seem to be the right thing to do?
<p>
Thank you.