Hi I need to replace in notepad++ 30 lines with new ones already copied, so each line gets replaced line by line.
These lines should be replaced:
5, 13, 21, 29, 37, 45, 53, 61, 69, 77, 85, 93, 101, 109, 117, 125, 133, 141, 149, 157, 165, 173, 181, 189, 197, 205, 213, 221, 229, 237
Example:
(5th line) https://signin.gg.com/p/web2/examplelinktestABC
(13th line) https://signin.gg.com/p/web2/examplelinktestABCD
(21th line) https://signin.gg.com/p/web2/examplelinktestABCDE1
(29th line) https://signin.gg.com/p/web2/examplelinktestABCDEF2
(37th line) https://signin.gg.com/p/web2/examplelinktestABCDEFGH
(45th line) https://signin.gg.com/p/web2/examplelinktestABCDE11
(53th line) https://signin.gg.com/p/web2/examplelinktestABCDE23
(61th line) https://signin.gg.com/p/web2/examplelinktestABCDE452
(69th line) https://signin.gg.com/p/web2/examplelinktestABCDE526
(77th line) https://signin.gg.com/p/web2/examplelinktestABCDE631
(85th line) https://signin.gg.com/p/web2/examplelinktestABCDE516
(93th line) https://signin.gg.com/p/web2/examplelinktestABCDE747
(101th line) https://signin.gg.com/p/web2/examplelinktestABCDE642
(109th line) https://signin.gg.com/p/web2/examplelinktestABCDE644
(117th line) https://signin.gg.com/p/web2/examplelinktestABCDE6243
(125th line) https://signin.gg.com/p/web2/examplelinktestABCDE6447
(133th line) https://signin.gg.com/p/web2/examplelinktestABCDE6723
(141th line) https://signin.gg.com/p/web2/examplelinktestABCDE7433
(149th line) https://signin.gg.com/p/web2/examplelinktestABCDE62672
(157th line) https://signin.gg.com/p/web2/examplelinktestABCDE62346
(165th line) https://signin.gg.com/p/web2/examplelinktestABCDE75384
(173th line) https://signin.gg.com/p/web2/examplelinktestABCDE8532
(181th line) https://signin.gg.com/p/web2/examplelinktestABCDE67355
(189th line) https://signin.gg.com/p/web2/examplelinktestABCDE734575
(197th line) https://signin.gg.com/p/web2/examplelinktestABCDE73455345
(205th line) https://signin.gg.com/p/web2/examplelinktestABCDE6734534
(213th line) https://signin.gg.com/p/web2/examplelinktestABCDE634537
(221th line) https://signin.gg.com/p/web2/examplelinktestABCDE74577
(229th line) https://signin.gg.com/p/web2/examplelinktestABCDE43423
(237th line) https://signin.gg.com/p/web2/examplelinktestABCDE5623623
And now while having all 30 new lines already copied, each line has to be replaced line by line.
So that's the effect after replacement:
(5th line) https://signin.gg.com/p/web2/examplelinktest11a1
(13th line) https://signin.gg.com/p/web2/examplelinktest22a1
(21th line) https://signin.gg.com/p/web2/examplelinktest33a1
(29th line) https://signin.gg.com/p/web2/examplelinktest44a1
(37th line) https://signin.gg.com/p/web2/examplelinktest55a1
(45th line) https://signin.gg.com/p/web2/examplelinktest66a1
(53th line) https://signin.gg.com/p/web2/examplelinktest77a1
(61th line) https://signin.gg.com/p/web2/examplelinktest88a1
(69th line) https://signin.gg.com/p/web2/examplelinktest99a1
(77th line) https://signin.gg.com/p/web2/examplelinktest111a1
(85th line) https://signin.gg.com/p/web2/examplelinktest222a2
(93th line) https://signin.gg.com/p/web2/examplelinktest333a3
(101th line) https://signin.gg.com/p/web2/examplelinktest444a4
(109th line) https://signin.gg.com/p/web2/examplelinktest555a5
(117th line) https://signin.gg.com/p/web2/examplelinktest666a6
(125th line) https://signin.gg.com/p/web2/examplelinktest777a7
(133th line) https://signin.gg.com/p/web2/examplelinktest888a8
(141th line) https://signin.gg.com/p/web2/examplelinktest999a9
(149th line) https://signin.gg.com/p/web2/examplelinktest1111a1
(157th line) https://signin.gg.com/p/web2/examplelinktest2222a2
(165th line) https://signin.gg.com/p/web2/examplelinktest3333a3
(173th line) https://signin.gg.com/p/web2/examplelinktest4444a4
(181th line) https://signin.gg.com/p/web2/examplelinktest5555a5
(189th line) https://signin.gg.com/p/web2/examplelinktest6666a6
(197th line) https://signin.gg.com/p/web2/examplelinktest7777a7
(205th line) https://signin.gg.com/p/web2/examplelinktest8888a8
(213th line) https://signin.gg.com/p/web2/examplelinktest9999a9
(221th line) https://signin.gg.com/p/web2/examplelinktest11111a1
(229th line) https://signin.gg.com/p/web2/examplelinktest22222a2
(237th line) https://signin.gg.com/p/web2/examplelinktest33333a3
Of course ---> (X line) is just an explanation where these lines are located , it should look like this after:
https://signin.gg.com/p/web2/examplelinktest11a1
https://signin.gg.com/p/web2/examplelinktest22a1
https://signin.gg.com/p/web2/examplelinktest33a1
https://signin.gg.com/p/web2/examplelinktest44a1
https://signin.gg.com/p/web2/examplelinktest55a1
https://signin.gg.com/p/web2/examplelinktest66a1
https://signin.gg.com/p/web2/examplelinktest77a1
https://signin.gg.com/p/web2/examplelinktest88a1
https://signin.gg.com/p/web2/examplelinktest99a1
https://signin.gg.com/p/web2/examplelinktest111a1
https://signin.gg.com/p/web2/examplelinktest222a2
https://signin.gg.com/p/web2/examplelinktest333a3
https://signin.gg.com/p/web2/examplelinktest444a4
https://signin.gg.com/p/web2/examplelinktest555a5
https://signin.gg.com/p/web2/examplelinktest666a6
https://signin.gg.com/p/web2/examplelinktest777a7
https://signin.gg.com/p/web2/examplelinktest888a8
https://signin.gg.com/p/web2/examplelinktest999a9
https://signin.gg.com/p/web2/examplelinktest1111a1
https://signin.gg.com/p/web2/examplelinktest2222a2
https://signin.gg.com/p/web2/examplelinktest3333a3
https://signin.gg.com/p/web2/examplelinktest4444a4
https://signin.gg.com/p/web2/examplelinktest5555a5
https://signin.gg.com/p/web2/examplelinktest6666a6
https://signin.gg.com/p/web2/examplelinktest7777a7
https://signin.gg.com/p/web2/examplelinktest8888a8
https://signin.gg.com/p/web2/examplelinktest9999a9
https://signin.gg.com/p/web2/examplelinktest11111a1
https://signin.gg.com/p/web2/examplelinktest22222a2
https://signin.gg.com/p/web2/examplelinktest33333a3
Thank you for any tips concerning this.
Related
Importing is behaving inconsistently and I'm pretty sure it's because of my meta_path loader.
My importer
class JaPyCodeImporter(object):
def __init__(self, modules):
self._modules = {}
self._last_module = None
modules = dict(modules)
for key in modules:
module_info = {}
module_info["full_name"] = key
module_info["source"] = modules[key]
module_info["code"] = compile(modules[key], key, "exec")
module_info["is_package"] = False
module_info["package"] = key.rpartition('.')[0]
if not key.rfind("__init__") == -1:
module_info["full_name"] = key[:key.rfind(".__init__")]
module_info["is_package"] = True
module_info["package"] = module_info["full_name"]
self._modules[module_info["full_name"]] = module_info
self._last_path = ""
def find_module(self, fullname, path):
if fullname in self._modules.keys():
print("Found: {0}".format(fullname))
return self
elif self._last_module and self._last_module["package"] + "." + fullname in self._modules.keys():
print("Found: {0} in package {1}".format(fullname, self._last_module["package"]))
return self
print("Couldn't find: {0}".format(fullname))
pdb.traceback.print_stack()
return None
def load_module(self, fullname):
expanded_name = self._last_path + "." + fullname
# check for pre-existence
if fullname in sys.modules:
return sys.modules[fullname]
elif self._last_module and self._last_module["package"] + "." + fullname in sys.modules:
return sys.modules[self._last_module["package"] + "." + fullname]
# check internally
if not fullname in self._modules.keys():
if self._last_module and not self._last_module["package"] + "." + fullname in self._modules.keys():
raise ImportError(fullname)
else:
fullname = self._last_module["package"] + "." + fullname
module_info = self._modules[fullname]
new_module = sys.modules.setdefault(fullname, imp.new_module(fullname))
new_module.__loader__ = self
new_module.__file__ = "<%s>" % self.__class__.__name__
new_module.__path__ = [] #module_info["package"].split(".")
new_module.__package__ = module_info["package"]
print("Loaded: {0}".format(module_info["full_name"]))
try:
self._last_module = self._modules[fullname]
print("Execute: {0}".format(module_info["full_name"]))
globals()["__name__"] = module_info["full_name"]
globals()["__package__"] = module_info["package"]
exec(self._modules[fullname]["code"], globals(), new_module.__dict__)
except SyntaxError as err:
error_class = err.__class__.__name__
detail = err.args[0]
line_number = err.lineno
print("%s at line %d of %s: %s" % (error_class, line_number, description, detail))
del sys.modules[fullname]
return None
except Exception as err:
error_class = err.__class__.__name__
detail = err.args[0]
print(detail)
cl, exc, tb = sys.exc_info()
line_number = traceback.extract_tb(tb)[-1][1]
print("%s at line %d of %s: %s" % (error_class, line_number, fullname, detail))
del sys.modules[fullname]
return None
return new_module
My file structure
gameSystem/
__init.__py
interface_bridge.py
libraries/
__init__.py
standard/
__init__.py
area.py
base_object.py
exit.py
player.py
Start of interface_bridge.py
print("*** begin interface_bridge.py ***")
# from https://github.com/jython/jython/blob/0a58cc26566d2b2334e80b2b3f2f42f6c738db2d/lib-python/2.7/ihooks.py
# line 424
print("__name__: {0}".format(globals()['__name__']))
# line 418
print("__package__: {0}".format(globals()['__package__']))
print("Begin imports")
import pickle
import io
import sys
print(dir(sys.modules[__name__]))
from . libraries.standard.player import Player
print(Player)
from . libraries.standard.player import Player # <- Line 22
#from . libraries.standard.area import Area
Yep, I'm literally trying to import Player a second time directly after the first. I'm doing that because I can see from the output that Player is imported correctly the first time. Regardless, if I use the second Player import or the commented Area import, the output is the same.
The output
*** begin interface_bridge.py ***
__name__: gameSystem.interface_bridge
__package__: gameSystem
Begin imports
Couldn't find: gameSystem.pickle
File "<iostream>", line 236, in loadGameData
File "<iostream>", line 116, in load_module
File "gameSystem.interface_bridge", line 13, in <module>
File "<iostream>", line 66, in find_module
Couldn't find: gameSystem.io
File "<iostream>", line 236, in loadGameData
File "<iostream>", line 116, in load_module
File "gameSystem.interface_bridge", line 14, in <module>
File "<iostream>", line 66, in find_module
Couldn't find: gameSystem.sys
File "<iostream>", line 236, in loadGameData
File "<iostream>", line 116, in load_module
File "gameSystem.interface_bridge", line 15, in <module>
File "<iostream>", line 66, in find_module
['__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', 'io', 'pickle', 'sys']
Found: gameSystem.libraries
Loaded: gameSystem.libraries
Execute: gameSystem.libraries
Found: gameSystem.libraries.standard
Loaded: gameSystem.libraries.standard
Execute: gameSystem.libraries.standard
Found: gameSystem.libraries.standard.player
Loaded: gameSystem.libraries.standard.player
Execute: gameSystem.libraries.standard.player
<class 'gameSystem.libraries.standard.player.Player'> <- Player class loaded!
Couldn't find: gameSystem.libraries.standard.libraries
File "<iostream>", line 236, in loadGameData
File "<iostream>", line 116, in load_module
File "gameSystem.interface_bridge", line 22, in <module>
File "<iostream>", line 66, in find_module
Couldn't find: gameSystem.libraries.standard.libraries
File "<iostream>", line 236, in loadGameData
File "<iostream>", line 116, in load_module
File "gameSystem.interface_bridge", line 22, in <module>
File "<iostream>", line 66, in find_module
No module named gameSystem.libraries.standard.libraries
ImportError at line 22 of gameSystem.interface_bridge: No module named gameSystem.libraries.standard.libraries
Those first three couldn't finds (pickle, io, and sys) all make sense as they are Python libraries (though it's interesting to see them being treated as if their part of the gameSystem package). My importer shouldn't handle them and kicks them back to the import system.
Then, as I interpret it, the import system starts working down the package structure (.libraries, .libraries.standard) to finally get to gameSystem.libraries.standard.player, which is loaded and executed without problem. You can see the class is ready to go as it can be printed to the output <class '...Player'>.
What happens next is where I get confused. Why is it trying to import gameSystem.libraries.standard.libraries? Why two times in a row?
I'm fairly certain this is caused by some mistake I've made in my importer but I'm baffled. I would expect both import lines to behave exactly the same way.
This question already has answers here:
Java: How to remove all line breaks between double quotes
(2 answers)
Closed 4 months ago.
I'm having a string containing CSV lines. Some of its values contains the CRLF characters, marked [CRLF] in the example below
NOTE: Line 1: and Line 2: aren't part of the CSV, but for the discussion
Line 1:
foo1,bar1,"john[CRLF]
dose[CRLF]
blah[CRLF]
blah",harry,potter[CRLF]
Line 2:
foo2,bar2,john,dose,blah,blah,harry,potter[CRLF]
Each time a value in a line have a CRLF, the whole value appears between quotes, as shown by line 1. Looking for a way to get ride of those CRLF when they appears between quotes.
Tried regexp such as:
data.replaceAll("(,\".*)([\r\n]+|[\n\r]+)(.*\",)", "$1 $3");
Or just ([\r\n]+) , \n+, etc. without success: the line continue to appears as if no replacement were made.
EDIT:
Solution
Found the solution here:
String data = "\"Test Line wo line break\", \"Test Line \nwith line break\"\n\"Test Line2 wo line break\", \"Test Line2 \nwith line break\"\n";
StringBuffer result = new StringBuffer();
Matcher m = Pattern.compile("\"[^\"]*\"").matcher(data);
while (m.find()) {
m.appendReplacement(result, m.group().replaceAll("\\R+", ""));
}
m.appendTail(result);
System.out.println(result.toString());
Using Java 9+ you can use a function code inside Matcher#replaceAll and solve your problem using this code:
// pattern that captures quoted strings ignoring all escaped quotes
Pattern p = Pattern.compile("\"[^\"\\\\]*(?:\\\\.[^\"\\\\]*)*\"");
String data1 = "\"Test Line wo line break\", \"Test Line \nwith line break\"\n\"Test Line2 wo line break\", \"Test Line2 \nwith line break\"\n";
// functional code to get all quotes strings and then remove all line
// breaks from matched substrings
String repl = p.matcher(data1).replaceAll(
m -> m.group().replaceAll("\\R+", "")
);
System.out.println(repl);
Output:
"Test Line wo line break", "Test Line with line break"
"Test Line2 wo line break", "Test Line2 with line break"
Code Demo
I'm trying to compare 2 strings, however my comparison always fails.
For reference, the one string is a filename I'm getting from the phones storage and it look like it ends with an apostrophe, although its not visible anywhere.
Please consider the following dart code:
import 'dart:convert';
void main() {
const Utf8Codec utf8 = Utf8Codec();
String input = 'chatnum.txt';
String stringwithapostrophe = 'chatnum.txt\'';
String compInput = utf8.encode(input).toString();
String compComp = utf8.encode(stringwithapostrophe).toString();
print (compInput);
print (compComp);
if (compInput == compComp) {
print ('Yes it matches');
} else {
print ('No it does not');
}
}
This output's a result of:
[99, 104, 97, 116, 110, 117, 109, 46, 116, 120, 116]
[99, 104, 97, 116, 110, 117, 109, 46, 116, 120, 116, 39]
No it does not
So how can I remove that last apostrophe from the String?
I've tried .removeAt and .removeLast. But I just can't crack this.
I applied regex to it. That sorted it:
String filenametosend = (basename(f.toString()))
.replaceAll(RegExp(r"[-!$%^&*()+|~=`{}##\[\]:;'’<>?,\/"
'"”'
"]"), '');
This way too:
final apostrophe = '\'';
final length = stringwithapostrophe.length;
if (length > 0 && stringwithapostrophe[length - 1] == apostrophe) {
stringwithapostrophe = stringwithapostrophe.substring(0, length - 1);
}
Or this way (remove all):
final apostrophe = '\'';
stringwithapostrophe = stringwithapostrophe.replaceAll(apostrophe, '');
Remove (any) last:
final length = stringwithapostrophe.length;
stringwithapostrophe = length > 0
? stringwithapostrophe.substring(0, length - 1)
: stringwithapostrophe;
I am trying to do this exercise but fail. I can only get this result:
main() File "C:\Users\chemuser\Desktop\KHL\python\chapter4_6.py", line 22, in main
asciimark = eval(line) File "<string>", line 1
^ SyntaxError: unexpected EOF while parsing
here is my fail code:
# -*- coding: cp1252 -*-
#A certain CS professor gives 5-point quizzes that are
#graded on the scale 5-A, 4-B, 3-C, 2-D, 1-F, 0-F.
#Write a program that accepts a quiz score as an
#input and prints out the corresponding grade.
import string
def main():
#set up file names
infileName = raw_input("input file name: ")
outfileName = raw_input("output file name: ")
#open files
infile = open(infileName, "r")
outfile = open(outfileName, "w")
#process each line of the input file
for line in infile.readlines():
#get the mark from line
asciimark = eval(line)
#creat grade
allgrade = "FEDCBA"
grade = allgrade[asciimark]
#write it to the output file
outfile.write(grade+"\n")
#close both files
infile.close()
outfile.close()
print "Done!"
main()
the input file is look like this (just a column of number 0 - 5, no blank line between):
5
1
0
2
3
I did a test, I add '/n' in the first line (5/n), it shows:
main() File "C:\Users\chemuser\Desktop\KHL\python\chapter4_6.py", line 22, in main
asciimark = eval(line) File "<string>", line 1
5\n
^ SyntaxError: unexpected character after line continuation character
your comments are very appreciated!!
I am looking for an elegant way to parse a file to blocks and for each block create a new file , for example :
original file:
line 1
line 2
line 3
line 4
line 5
line 6
line 7
result:
first file:
line 1
second file:
line 2
line 3
third file:
line 4
line 5
line 6
fourth file:
line 7
thanks
It looks like you could use this algorithm:
Count the number of spaces at the beginning of each line, if it's less than or equal to the number of spaces in the preceding non-empty line, open a new file.
What have you tried so far?
You could use scoped_ptrs to change the output file when the input line does not begin with whitespace:
std::ifstream in("/your/input/file");
boost::scoped_ptr<std::ofstream> out(NULL)
int out_serial = 0;
std::string line;
while(std::getline(in, line))
{
// test: first character non blank
if(! line.empty() && (line.at(0) != ' ' && line.at(0) != '\t'))
{
std::ostringstream new_output_file;
new_output_file << "/your/output/file/prefix_" << out_serial++;
out.reset(new std::ofstream(new_output_file.str()));
}
if(out.get() != NULL) (*out) << line << std::endl;
}
If your code is not properly intended or your blocks are only based on braces not spaces, you can use a stack(STL). Push on opening brace and Pop on closing brace. Open a new file each time the stack become empty