encode in UTF-8-BOM

Dear all,

I have some files coded as UTF-8 and I want to convert in UTF-8-BOM.

In vernalis “url decode” I don’t see the UTF-8-BOM.

I found a solution using Python with the following script:

s= open(r"C:\XXX\file.yml", mode=“r”, encoding=“utf-8”).read()
open(r"C:\XXX\file.yml", mode=“w”, encoding=“utf-8-sig”).write(s)

How I can implement this in “python script” node?
I wish put this script in loop where the URL of the files in input change with the iterarion and the file will be saved with the BOM
also what I have to put in output in this case?

I’m a noob in python so i need help

thanks

Hi @baarzo -

Sorry for the lengthy delay in replying here.

First things first, to use Python from within KNIME, you need to do some configuration of your Python environment. That’s described in our documentation here.

Next, you would need to use a Python Snippet node to apply your code. And you mentioned you want to do this in a loop to convert each file one at a time. Here’s an example workflow:

2020-02-10 13_12_44-KNIME Analytics Platform

PythonUTFEncodingExample.knwf (14.2 KB)

I’m not a Python expert either, but maybe this will help you get started.

(Also, since this isn’t a text processing issue per se, I’ve moved this to the main KNIME forum for better visibility, in case it may help someone else later.)

2 Likes