I'm quite new to Python Script for NPP, butI think i go fine with regexes, python and notepad++ itself.
I want to make a simple task automatic for data conversion between two different database types, with different fields and different values also. I was thinking that npp + automatic replace will do the job for me, but it seems like not working.
First of all, sometimes notepad++ throws an unhandled exception and simply crashes when running the script (Win 10 64 Bit).
But if it does not, the script goes wrong 9 times from 10, but not at the same place in the file. The data is surely not corrupt, because fail occurs on different records.
I export the data from the original db to JSON, and run this simple script on it:
Npp.editor.rereplace('},','},\n')
Npp.console.write("\n1 record 1 line - OK\n")
sometimes it catches a record, and cut it somewhere, and insert it somewhere else (like part of the 25500th record is between the 12345th and 12346th one, and the other part stays where it belongs to. But this messes up the whole JSON.
almost every time from a different record nr (but mostly over 10k and under 25k) it starts to place two "}" instead of one.
sometimes it replaces line endings with unsupported characters (some interesting things, unreadable characters occur instead of line breaks), moreover when i see these, the app crashes every time too.
The file is about 4.5 MB, and contains 30-40k records, at first time in a single line, this would be the step what gives each record a different line. The script itself does not fail, it writes to the console, moreover if i insert other replacements (like getting ride of some variables, or changing the name of some others), it work well. Seems like only this part is messing up the whole think.
Does anyone has any idea what's happening? What am i missing? Could my regex be wrong?
Thanks for answering,
D K
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I assume you wanna replace the literals }, with },\n
If so, the regex is incorrect as } is a known regex operator char (repeating operator) and therefore you
need to escape it in order to treat it as a literal. So I guess the regex engine gets
called too many times with closing repeating char and then at some point npp crashes.
Not nice but ...
In addition, you don't need to add Npp in front of your calls editor.rereplace('},','},\n')
should work as well.
Btw. in order to test your regex I would recommend to take a little amount of your data
put it into an document, open the console and test your call. Most of the times you will
get useful error hints.
Cheers
Claudia
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
btw. there is a known issue that the backup functionality might jump in wile doing replacing and under some strange circumstances it corrupts the doc content. Not sure if this has been fixed with latest version but I normally disable backup
when editing big files.
Cheers
Claudia
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I was going to suggest making sure you're on the latest version. These
issues should be fixed - you should be on 1.0.8, which can only be properly
installed with the msi until the new plugin manager is released. If you're
on the latest version, I'd be really grateful if you could share the
document (privately if you'd prefer)
We should be rid of these issues, if they still exist we need to track them
down!
btw. there is a known issue that the backup functionality might jump in
wile doing replacing and under some strange circumstances it corrupts the
doc content. Not sure if this has been fixed with latest version but I
normally disable backup
when editing big files.
Just to be sure, you responded to the original poster, didn't you?
You are right, I nearly forgot that there was an issue with the older python script version.
Cheers
Claudia
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
First of all, I'm currently escaping the '}' brackets, maybe the text editor here removed them. My script was looking like this (originally, before Claudia's suggestion too).
Npp.editor.rereplace('\},','\},\n')
Will try to check this for a smaller file with about 1-200 entries only.
And Dave, thanks for mentioning that i did not annotated the code here, will do that in the future.
I will share the document privately with you, Dave.
My version is 1.0.6.0., could this be the problem? Installed via plugin manager.
Have a nice day,
D K
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi folks,
I'm quite new to Python Script for NPP, butI think i go fine with regexes, python and notepad++ itself.
I want to make a simple task automatic for data conversion between two different database types, with different fields and different values also. I was thinking that npp + automatic replace will do the job for me, but it seems like not working.
First of all, sometimes notepad++ throws an unhandled exception and simply crashes when running the script (Win 10 64 Bit).
But if it does not, the script goes wrong 9 times from 10, but not at the same place in the file. The data is surely not corrupt, because fail occurs on different records.
I export the data from the original db to JSON, and run this simple script on it:
Npp.editor.rereplace('},','},\n')
Npp.console.write("\n1 record 1 line - OK\n")
sometimes it catches a record, and cut it somewhere, and insert it somewhere else (like part of the 25500th record is between the 12345th and 12346th one, and the other part stays where it belongs to. But this messes up the whole JSON.
almost every time from a different record nr (but mostly over 10k and under 25k) it starts to place two "}" instead of one.
sometimes it replaces line endings with unsupported characters (some interesting things, unreadable characters occur instead of line breaks), moreover when i see these, the app crashes every time too.
The file is about 4.5 MB, and contains 30-40k records, at first time in a single line, this would be the step what gives each record a different line. The script itself does not fail, it writes to the console, moreover if i insert other replacements (like getting ride of some variables, or changing the name of some others), it work well. Seems like only this part is messing up the whole think.
Does anyone has any idea what's happening? What am i missing? Could my regex be wrong?
Thanks for answering,
D K
I assume you wanna replace the literals }, with },\n
If so, the regex is incorrect as } is a known regex operator char (repeating operator) and therefore you
need to escape it in order to treat it as a literal. So I guess the regex engine gets
called too many times with closing repeating char and then at some point npp crashes.
Not nice but ...
In addition, you don't need to add Npp in front of your calls editor.rereplace('},','},\n')
should work as well.
Btw. in order to test your regex I would recommend to take a little amount of your data
put it into an document, open the console and test your call. Most of the times you will
get useful error hints.
Cheers
Claudia
btw. there is a known issue that the backup functionality might jump in wile doing replacing and under some strange circumstances it corrupts the doc content. Not sure if this has been fixed with latest version but I normally disable backup
when editing big files.
Cheers
Claudia
I was going to suggest making sure you're on the latest version. These
issues should be fixed - you should be on 1.0.8, which can only be properly
installed with the msi until the new plugin manager is released. If you're
on the latest version, I'd be really grateful if you could share the
document (privately if you'd prefer)
We should be rid of these issues, if they still exist we need to track them
down!
On Tue, 18 Oct 2016, 15:08 CFrank, myxin2010@users.sf.net wrote:
Just to be sure, you responded to the original poster, didn't you?
You are right, I nearly forgot that there was an issue with the older python script version.
Cheers
Claudia
Hi there, thanks for answering!
First of all, I'm currently escaping the '}' brackets, maybe the text editor here removed them. My script was looking like this (originally, before Claudia's suggestion too).
Will try to check this for a smaller file with about 1-200 entries only.
And Dave, thanks for mentioning that i did not annotated the code here, will do that in the future.
I will share the document privately with you, Dave.
My version is 1.0.6.0., could this be the problem? Installed via plugin manager.
Have a nice day,
D K