Re: add characters at the beginning and end of many lines in a text

2020-11-10 Thread AudioGames . net Forum — Off-topic room : john via Audiogames-reflector


  


Re: add characters at the beginning and end of many lines in a text

This is a great opportunity to take advantage of nvda's on-the-fly python availability, presuming that what you're dealing with here are plain text files.If that's the case, the script below should do what you want: copy everything from the line starting with def to the bottom of my post (it'll end with the line saying the file was saved), fill in the quotes as directed, paste it into nvda's python console (nvda->tools->python console), and press enter so it puts you back at a command prompt.Then, just type addtext() and hit enter.If all works correctly, you'll promptly get a notification that the new file was saved, and you're good to go.The only thing to remember is that you need to give absolute paths as your file names, for exampleoriginal="c:\users\me\documents\dictionary.txt"I hope this helps - and if any of the python-using folks on here want to write a better version, please do feel free (and I'll remove the worse one).def addtext(): original=""#fill the quotes in with the full path to the file you want to modify newfile=""#fill the quotes in with the full path of the file you want to create prefix=""#Fill the quotes in with the text you want at the start of each line suffix=""#Fill the quotes in with the text you want at the end of each line f=open(original,"r") lines=f.readlines() f.close() if(lines[-1][-1]!="\n"):  lines[-1]+="\n" f=open(newfile,"w") for line in lines:  f.write(prefix+line[:-1]+suffix+"\n") f.close() print(newfile+" saved.")

URL: https://forum.audiogames.net/post/588650/#p588650




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: add characters at the beginning and end of many lines in a text

2020-11-10 Thread AudioGames . net Forum — Off-topic room : john via Audiogames-reflector


  


Re: add characters at the beginning and end of many lines in a text

This is a great opportunity to take advantage of nvda's on-the-fly python availability, presuming that what you're dealing with here are plain text files.If that's the case, the script below should do what you want: copy everything from the line starting with def to the bottom of my post (it'll end with the line saying the file was saved), fill in the quotes as directed, paste it into nvda's python console (nvda->tools->python console), and press enter so it puts you back at a command prompt.Then, just type addtext() and hit enter.If all works correctly, you'll promptly get a notification that the new file was saved, and you're good to go.The only thing to remember is that you need to give absolute paths as your file names, for exampleoriginal="c:\users\me\documents\dictionary.txt"I hope this helps - and if any of the python-using folks on here want to write a better version, please do feel free (and I'll remove the worse one).def addtext(): original=""#fill the quotes in with the full path to the file you want to modify newfile=""#fill the quotes in with the full path of the file you want to create prefix=""#Fill the quotes in with the text you want at the start of each line suffix=""#Fill the quotes in with the text you want at the end of each line f=open(original,"r") lines=f.readlines() f.close() if(lines[-1][-1]!="\n"):  lines[-1]+="\n" f=open(newfile,"w") for line in lines:  f.write(prefix+line[:-1]+suffix+"\n")#if somebody wants to rewrite this with format strings, go for it and I'll remove the slower version f.close() print(newfile+" saved.")

URL: https://forum.audiogames.net/post/588650/#p588650




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


Re: add characters at the beginning and end of many lines in a text

2020-11-10 Thread AudioGames . net Forum — Off-topic room : john via Audiogames-reflector


  


Re: add characters at the beginning and end of many lines in a text

This is a great opportunity to take advantage of nvda's on-the-fly python availability, presuming that what you're dealing with here are plain text files.If that's the case, the script below should do what you want: copy everything from the line starting with def to the bottom of my post (it'll end with the line saying the file was saved), fill in the quotes as directed, paste it into nvda's python console (nvda->tools->python console), and press enter so it puts you back at a command prompt.Then, just type addtext() and hit enter.If all works correctly, you'll promptly get a notification that the new file was saved, and you're good to go.The only thing to remember is that you need to give absolute paths as your file names, for exampleoriginal="c:\users\me\documents\dictionary.txt"I hope this helps - and if any of the python-using folks on here want to write a better version, please do feel free (and I'll remove the worse one).def addtext(): original=""#fill the quotes in with the full path to the file you want to modify newfile=""#fill the quotes in with the full path of the file you want to create with the modifications prefix=""#Fill the quotes in with the text you want at the start of each line suffix=""#Fill the quotes in with the text you want at the end of each line f=open(original,"r") lines=f.readlines() f.close() if(lines[-1][-1]!="\n"):  lines[-1]+="\n" f=open(newfile,"w") for line in lines:  f.write(prefix+line[:-1]+suffix+"\n")#if somebody wants to rewrite this with format strings, go for it and I'll remove the slower version f.close() print(newfile+" saved.")

URL: https://forum.audiogames.net/post/588650/#p588650




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector


add characters at the beginning and end of many lines in a text

2020-11-10 Thread AudioGames . net Forum — Off-topic room : Diego via Audiogames-reflector


  


add characters at the beginning and end of many lines in a text

Hello guys!I'm trying to export a dictionary made to NVDA so that it works in eloquence for android, and I need to add characters at the beginning and at the end of thousands of lines.How to do this?

URL: https://forum.audiogames.net/post/588616/#p588616




-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector