Goodbying Spaces

Victor Subervi victorsubervi at gmail.com
Tue Apr 29 14:57:37 CEST 2008


On Fri, Apr 25, 2008 at 4:29 PM, Luis Zarrabeitia <kyrie at uh.cu> wrote:

>
> Whats the result of using id.strip()?:
>
> In [1]: " asdfasdf   ".strip()
> Out[1]: 'asdfasdf'
>
> It should work, I guess...


It didn´t for some reason. That was the first thing I tried.

>
>
> Btw, you can write your code without using len in a cleaner way:
>
> try:
>  if id[0] == ' ':
>    id = id[1:]   # Note this slice notation...
> except:
>  pass
>
> try:
>  if id[-1] == ' ':   # id[-1] would be the last character
>    id = id[:-1]      # Again, a slice with only one argument
> except:
>  pass


Oh, yeah. Forgot about that. Thanks!
Victor
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20080429/f02b1cef/attachment.html>


More information about the Python-list mailing list