string.split bug?

Hameed Khan hameedkhaan at yahoo.com
Wed Feb 25 03:03:01 EST 2004


hi,
  i am not a python expert i am just a beginner and i
am taking part in thi discussion because i have
encounter the same problem just a week ago. and from
my experiments on different types of strings i have
concluded that python returns and extra empty string
as a last item when we provided delimeter to split()
function. and when we dont provide delimeter to
split() it checks the common delimeter (i think it
only looks for newline and whitespace delimeters) in
string and then splits the string according to that
delimeter and didn't return any extra empty string as
a last item in the list it returns.

Thanks,
Hameed.
------------------------------

Message: 5
Date: 24 Feb 2004 23:08:06 -0800
From: jcb at iteris.com (MetalOne)
Subject: string.split bug?
To: python-list at python.org
Message-ID:
<92c59a2c.0402242308.35f55d4a at posting.google.com>
Content-Type: text/plain; charset=ISO-8859-1

string.split("") ==> []
string.split("",",") ==> ['']

I did not expect these to have different outputs.

I have a string with comma delimited numbers.
There can be zero or more numbers in the string
s = "0x41, 0x42"

I wanted to do
numbers = map(lambda x: int(x,16),
string.split(s,","))

However, when there are no numbers, this generates an
error.


------------------------------


__________________________________
Do you Yahoo!?
Yahoo! Mail SpamGuard - Read only the mail you want.
http://antispam.yahoo.com/tools




More information about the Python-list mailing list