[Tutor] Re: all the slashes

Gerhard Venter loper at ananzi.co.za
Tue Feb 10 04:06:26 EST 2004


Hi

I was not trying to escape it, I was testing for two slashes as in 
http://www.ripe.net
So I ended up using:
if DomainName.find(r'//') > -1:

as was also suggested by Andrei

Thanks
Gerhard



Abel Daniel wrote:

>Gerhard Venter  writes:
>
>  
>
>>Hi all
>>
>>I use the code below in Python 2.3, but in 2.2 it says:
>>TypeError: 'in <string>' requires character as left operand
>>I have tried r'//',  and '////' (to escape the slashes) to no avail.
>>
>>     myfile=open(r'/etc/sitelist','a')
>>     if "//" in mystring:
>>
>>    
>>
>Why would you need to escape it?
>
>  
>
>>>>'/' in 'ab/c'
>>>>        
>>>>
>True
>  
>
>>>>'/' in 'abc'
>>>>        
>>>>
>False
>  
>
>
>OTOH, if you would be looking for \ -s (backslashes) you would need to escape
>it:
>  
>
>>>>'\' in 'ab\c'
>>>>        
>>>>
>  File "<stdin>", line 1
>    '\' in 'ab\c'
>             ^
>SyntaxError: invalid syntax
>  
>
>>>>'\\' in 'ab\c'
>>>>        
>>>>
>True
>  
>
>
>Plus, if you do use the code you showed, then you have a bug: your version
>is looking for '//' (two slashes) and not '/' (one slash).
>
>  
>




More information about the Tutor mailing list