I'm working with a file that contains some lines with backslash characters, such as "moz\\123\\". I have each line then stored in a dictionary and later compared to the original line in the file. The problem is that Python inputs into the dictionary a key with double the number of backslashes (instead of "moz\\123\\", I get "moz\\\\123\\\\") so when doing the comparison between the original line and the key in the dictionary, the original cannot be found because the key is different. How can I handle this problem? Here is some code:
my_dict={}
def reader():
inputfile=open('<filepath>', 'r')
for line in inputfile:
my_dict[line]=0
print(my_dict)
reader()
where filepath contains
the
here
moz\\12\\14
the\
and the print statement gives
{'here\n': 0, 'the\\': 0, 'the\n': 0, 'moz\\\\12\\\\14\n': 0}.