[Tutor] Fwd: RE: wierd replace problem

bob gailer bgailer at gmail.com
Mon Sep 13 17:33:23 CEST 2010


  Forwarding to the list.

	

	

	

	


----------------------------------------
>  Date: Mon, 13 Sep 2010 11:07:19 -0400
>  From: bgailer at gmail.com
>  To: tutor at python.org
>  Subject: Re: [Tutor] wierd replace problem
>
>  On 9/13/2010 8:19 AM, Roelof Wobben wrote:
>>  Hello,
>>
>>  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()
>>  letter_items.sort()
>>  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.
>  I ran your program against a 1 line file containing 'het is een wonder
>  \\TIS'
>  The result I get is [('een', 1), ('het', 1), ('is', 1), ('tis', 1),
>  ('wonder', 1)]
>
>  Dunno why you are getting a different result.
>
>  Here is where using the debugger and going step by step can help. I have
>  no experience with the IDLE debugger. Perhaps others can offer advice on
>  that.
>  istinfo/tutor


Hello everyone.

Chancing to (r\\, '') or (\\\\, '') did not help.

I know that there were more outcome. I would only let see that on the python prompt the \ is deleted and if I use Eclipse the / stays when I use the text from alice in wonderland.

And im still wondering why this happens.
Maybe put the text from alice into the python prompt and look what happens.

Roelof
   		 	   		

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20100913/9878aa75/attachment-0001.html>


More information about the Tutor mailing list