To be honest, I don't think that reading a file once and using its content in a list is slower than opening the substitution file always, if you tested this with more than one file. But a general question, all that you want to do is to find some text and replace it, correct? If so, why not using ... notepad.open(fileName.encode('utf-8')) for s in sl editor.replace(s[0],s[1]) notepad.save() notepad.close() There is no need for doing findText, saving position ... first. Another hint, you can define...
Well than you need to find out what encoding has been used, which, btw, cannot be done in a 100% save manner. Npp uses chardet to identify the encoding, chardet is also available as python module. If only utf8 with or without BOM is used, than you can use codecs module and do something like import codecs with codecs.open(u'FILENAME') as f: for l in f: if len(l) > 1: s = l.split() if s[0].startswith(codecs.BOM_UTF8): _s = s[0][len(codecs.BOM_UTF8):].decode('utf-8') else: _s = s[0] ... Cheers Clau...
Why not converting your file to UTF-8 (without the BOM). Cheers Claudia
yep, another possible way :-D
get/setProperty is normally used to get/set lexer specific properties like allow folding etc... Recently npp added fold.quotes.python property to allow doc comments to be folded, this wasn't possible before unless you would have set it with python script for example. But this gaves also the possibility to add any info/value you want to a document and it is only avaliable through the lifetime of that document. Once document closes everything is gone and you don't have to take care of it.(well, in...
Correct, setProperty is per document as globals() returns the current global scope which is used by every script you run as long as your in the same namespace. Scott, I think moon refers to my example where I used 42 in setProperty call.
You could use the global namespace or the editor.setProperty function to save data need on subsequent calls global namespace: counter = globals().get('counter', 1) t = globals().get('t', 'set') print '{} {}'.format(t, counter) counter += 1 or editor.setProperty('MY_VAR','42') print editor.getProperty('MY_VAR')
@Moon, After rereading my post I guess I was a bit unclear - yes, getTag(number) rerturns a submatch but there is no function to retrieve how many submatches were catched. Sorry for confusion.