Jul-20-2023, 04:53 PM
Hi all! Regards!
I'm new at Python ecossystem and some days behind i got a problem.
I'm using Python 3.12 at W10
'My' bug is shown by following code:
# Is this really a bug, or did i misunderstood .split() specifications ?

I'm new at Python ecossystem and some days behind i got a problem.
I'm using Python 3.12 at W10
'My' bug is shown by following code:
# The problem is on use of ''.split() vs ''.split( ' ' ) exp = ['a', 'b'] # expected result list def check( a, x ) : global exp if x == exp : res = 'ok' else : res = 'error' print( "a='%s' -> %s ( expected : %s .. %s )\n" % (a,x,exp,res) ) print( '-'*24, " Using ''.split() ", '-'*24, '\n' ) a = 'a b' # one space separating tokens x = a.split() check( a, x ) a = 'a b' # two spaces separating tokens x = a.split() check( a, x ) a = 'a b' x = a.split() # three spaces separating tokens check( a, x ) print( '-'*22, " Using ''.split(' ') ", '-'*23, '\n' ) a = 'a b' x = a.split(' ') check( a, x ) # one space separating tokens a = 'a b' # two spaces separating tokens x = a.split(' ') check( a, x ) a = 'a b' # three spaces separating tokens x = a.split(' ') check( a, x ) print( '-'*68, '\n' )#### MY RESULTS ####



Output:------------------------ Using ''.split() ------------------------
a='a b' -> ['a', 'b'] ( expected : ['a', 'b'] .. ok )
a='a b' -> ['a', 'b'] ( expected : ['a', 'b'] .. ok )
a='a b' -> ['a', 'b'] ( expected : ['a', 'b'] .. ok )
---------------------- Using ''.split(' ') -----------------------
a='a b' -> ['a', 'b'] ( expected : ['a', 'b'] .. ok )
a='a b' -> ['a', '', 'b'] ( expected : ['a', 'b'] .. error )
a='a b' -> ['a', '', '', 'b'] ( expected : ['a', 'b'] .. error )
--------------------------------------------------------------------

# Is this really a bug, or did i misunderstood .split() specifications ?