[Tutor] wierd replace problem

Roelof Wobben rwobben at hotmail.com
Mon Sep 13 14:19:23 CEST 2010


I have this string called test with the contents of 'het is een wonder \\TIS'

Now I want to get rid of the \\ so I do this : test2 = test.replace ('\\', '')
And I get at the python prompt this answer : 'het is een wonder TIS' 
So that's right.

Now I try the same in a IDE with this programm :
woorden =[]
letter_counts = {}
file = open ('alice_in_wonderland.txt', 'r')
for line in file:
    line2 = line.replace ("\\","")
    line3 = line2.lower()
    woorden = line3.split()
    for letter in woorden:
        letter_counts[letter] = letter_counts.get (letter, 0) + 1
letter_items = letter_counts.items()
print letter_items 
But now Im gettting this output :
[('"\'tis', 1), 
Why does the \ stays here. It should have gone as the test in the python prompt says.


More information about the Tutor mailing list