Jul-20-2023, 04:53 PM
(This post was last modified: Jul-20-2023, 04:57 PM by deanhystad.)
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 ?
deanhystad write Jul-20-2023, 04:57 PM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.