I use “writefile” to create a new file and write a string to it. But the encoding of the new file seems not be be controlled by settings in Preference > Internationalization > Language-specific Default Encoding.
os.writefile(myOutput, content);
Is there any way to force UTF-8 encoding on the newly created file (myOutput)?
var content = ko.views.manager.currentView.scimoz.text;
var myOutput = "C:\\000\\aaa3.txt";
var os = Components.classes["@activestate.com/koOs;1"].getService(Components.interfaces.koIOs);
os.writefile(myOutput, content);
If content is “aaa”, the output file is a good file with UTF-8.
If content is “aaöaaa”, the output file is corrupt.
I’m not able to able to reproduce an issue using koOS but you could try using the JS SDK instead:
var content = ko.views.manager.currentView.scimoz.text;
var myOutputFile = require("ko/file").open("C:\\000\\aaa3.txt", "w")
myOutputFile.write(content)
myOutputFile.close()
FYI, the service you used is using Python to open(path, 'wb').write(content). Komodo preferences have no effect on using this method to write to a file.
I had accumulated a lot of scripts during last years. I’m afraid it would be a formidable project to adapt them to newer versions of Komodo. That’s why I still work with v.7.
@surfactant have you tried migrating yet? We haven’t phased out any legacy libraries so all your code SHOULD work. If you haven’t tried it might be work a shot. Komodo 11 is free by just creating an account on the new Active State platform right now: https://platform.activestate.com/
If you’re not into upgrading, can you clarify how you’re creating the file?
@careyh About 3 years ago, I tried a newer version, but ran into some problems. After that I went back to v.7.
I don’t know what you mean by “creating the file”. Very often I use Komodo to manipulate web pages by RegEx batchwise, but not as a programming tool. I must say that Komodo is really great for the job.
I’m clarifying this comment. You don’t create the file manually, correct? Running writefile results in a new file? I’m not able to reproduce the issue so I want to try and figure out what we’re missing from your workflow that might be causing the issue. So far, from what i see, your use case should work fine. using writefile to write “aaöaaa” to a file shouldn’t corrupt the file.
create test.txt, paste aaöaaa in it and save it with UTF-8.
open test.txt in Komodo
run the script, and aaa3.txt is generated.
var content = ko.views.manager.currentView.scimoz.text;
var myOutput = “C:\\000\\aaa3.txt”;
var os = Components.classes["@activestate.com/koOs;1"].getService(Components.interfaces.koIOs);
os.writefile(myOutput, content);
I’m still not able to reproduce the issue. In step 1 are you using Komodo to create test.txt or something else? I used Komodo.
Everything works fine for me. We’re missing something.
This is the output from my JS console session in Komodo.
var path = "C:\\Users\\cgcho\\Projects\\TEMP\\aaa3.txt"
var view = require("ko/views").current().get()
var content = view.scimoz.text
content
String
"aaöaaa"
var os = Components.classes["@activestate.com/koOs;1"].getService(Components.interfaces.koIOs)
os.writefile(path, content)