0

No matter what I try, this string is not split.

def funktion():
    ser = serial.Serial('COM5',115200)
    b = str("Das ist ein Test")
    a = str(ser.readline().decode())
    b.split(' ')
    a.split('s')
    print (a)
    print (b)

enter image description here

chepner
  • 497,756
  • 71
  • 530
  • 681
DjEKI
  • 11
  • 2

2 Answers2

7

String aren't mutable, so you have to re-assign those:

b = b.split(' ')
a = a.split('s')
print(a)
print(b)

See more on Immutable vs Mutable types SO question and in that article.

Community
  • 1
  • 1
Andriy Ivaneyko
  • 20,639
  • 6
  • 60
  • 82
1

the split function does not change the string in-place. it returns a new string. you must do tokens = b.split(' '); print(b) instead.

blue_note
  • 27,712
  • 9
  • 72
  • 90