Am I missing something?

Am I being “not smart”.

why is the split function not working

It just returns an empty list.

1 Like

It looks like it’s giving an error from a place you can’t control, since you’re not using “length” in your program.

Cannot read property ‘length’ of undefined
at (main.ts:1:1)

It works in JavaScript…

Yes I know but it should work in python
.split(" ") works the same in both languages,
but in python for some reason it is returning []
which the obviously
returns an error
can this be fixed?

Yeah, it should. If it still doesn’t work on Monday, I’ll check in with the team.

The split is still not working. What’s wrong with using it?

I don’t think Python currently supports split() on strings. I’ve opened an “issue” on GitHub to report the error. See here:

In the meantime, you could use a function to split strings by a single character. Here’s an example (I’ve tested it in the simulator, but not on a micro:bit):

words = "this is a test"

def simpleSplit(string, char):
    array = []
    current = ""
    for c in string:
        if c==char: 
            current = ""
            current = current + c 
    if current != "":
    return array

splitBySpace = simpleSplit(words, " ")
for w in splitBySpace:

The GitHub issue has been closed. It looks like split() in Python may now work: .