Menu

cannot use notepad.open

Help
Chris
2017-06-19
2017-06-19
  • Chris

    Chris - 2017-06-19

    Dear all,

    I write a python script which help me to convert all files in UTF-8 without BOM in specific extension. However, the error is stopped on the statement of notepad.open(fileName), the error seem I am missing of argument of unicode, but I search in python script, the notepad.open should pass the filename only. I currently usePhython Script version 1.0.8, do you know why?

    Thanks all.

    The error in Console

      File "C:\Users\Chris\AppData\Roaming\Notepad++\plugins\Config\PythonScript\scripts\Convert file to UTF-8 without BOM.py", line 12, in <module>
        notepad.open(fileName)
    Boost.Python.ArgumentError: Python argument types in
        Notepad.open(Notepad, unicode)
    did not match C++ signature:
        open(class NppPythonScript::NotepadPlusWrapper {lvalue}, char const * filename)
    

    Source code

    # -*- coding: UTF-8 -*-
    import os;
    import sys;
    filePathSrc = u'D:\\TEMP\\a'
    console.write('Source: ' + filePathSrc + '\n')
    for root, dirs, files in os.walk(filePathSrc):
        for fn in files:
            if fn[-4:] == '.srt' or fn[-4:] == '.ssa' or fn[-4:] == '.ass':
                fileName = root + "\\" + fn
                console.write("fileName: " + fileName + '\n')
                notepad.open(fileName)
                notepad.runMenuCommand("Encoding", "Convert to UTF-8 without BOM")
                notepad.save()
                notepad.close()
    
     
  • CFrank

    CFrank - 2017-06-19

    By using
    filePathSrc = u'D:\TEMP\a'
    you turn everything returned by os.walk into a unicode string but
    open function expects normal byte string.

    Use filePathSrc = 'D:\TEMP\a' instead.

    Cheers
    Claudia

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.