Sublime Forum

Reopen file or apply encoding

#1

I am new to python so I probably make some rookie mistake.

The file I am trying to work on has some binary part and open in hexadecimal view by default. I try to do a script that apply a DOS (CP 437) encoding, do some operation on the string and apply a UTF-16 BE encoding. Windows open the files in sublimetext and I want users to run a scipts when they open those files so I want to minimize the amount of clicks and operation to explain

Just setting the encoding does not change the view. The string operation work when I am in DOS encoding but I have problem with applying the encoding. When I manually open the file and run the script, save it and manually reopen the file it works. I tried reopining the file with the good encoding in the script but the operation does not work and does not show me errors.

My class begin with
Class MyClassCommand(sublime_plugin.TextCommand)
def run(self, edit)

I tried

self.view.run_command (“open_with_encoding”,{“encoding”:“DOS (CP 437)”,“filename”:myfilevariable} )

self.view.run_command (“reopen”, “UTF-16 BE”)

and other variation of variable like openwithencoding without underscore, window instead of view, creating another class with a different sublime_plugin.WindowCommand or sublime_plugin.ApplicationCommand but I cannot find the good syntax that execute the command

0 Likes