471,091 Members | 1,553 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,091 software developers and data experts.

Re: Goodbying Spaces


Whats the result of using id.strip()?:

In [1]: " asdfasdf ".strip()
Out[1]: 'asdfasdf'

It should work, I guess...

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

Cheers,

K.

On Friday 25 April 2008 05:01:31 pm Victor Subervi wrote:
Hi;
Whenever I call a field from the preceeding form using cgi.FieldStorage()I
get a space on either side. I end up writing code like this to get rid of
that space:

try:

if id[0] == ' ':

id = id[1:len(id)]

except:

pass

try:

if id[len(id) - 1] == ' ':

id = id[0:len(id) - 1]

except:

pass
which is a nuisance. Is there a better way to do this? I have tried
id.strip() with no luck. What do?
TIA,
Victor


--
Luis Zarrabeitia (aka Kyrie)
Fac. de Matemática y Computación, UH.
http://profesores.matcom.uh.cu/~kyrie
Jun 27 '08 #1
0 585

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Michael Bulatovich | last post: by
11 posts views Thread by gopal srinivasan | last post: by
135 posts views Thread by Xah Lee | last post: by
3 posts views Thread by Luke - eat.lemons | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.