# Am I missing something?

**URL:** <https://forum.makecode.com/t/am-i-missing-something/4659>\
**Category:** micro:bit\
**Created:** [November 27, 2020, 1:51am UTC](https://forum.makecode.com/t/am-i-missing-something/4659 "2020-11-27T01:51:14Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![charliegregg](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/charliegregg/32/2411_2.png) [@charliegregg](https://forum.makecode.com/u/charliegregg)\
**Post date:** [November 27, 2020, 1:51am UTC](https://forum.makecode.com/t/am-i-missing-something/4659/1 "2020-11-27T01:51:14Z")

</div>

> **[Test](https://makecode.microbit.org/00490-67801-93991-99094)**
>
> Made with ❤️ in Microsoft MakeCode for micro:bit.

Am I being “not smart”.

why is the split function not working

It just returns an empty list.

---

<div class="post-metadata">

**Author:** ![KIKIvsIT](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/kikivsit/32/10492_2.png) [@KIKIvsIT](https://forum.makecode.com/u/KIKIvsIT)\
**Post date:** [November 27, 2020, 3:40am UTC](https://forum.makecode.com/t/am-i-missing-something/4659/2 "2020-11-27T03:40:38Z")

</div>

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)

---

<div class="post-metadata">

**Author:** ![KIKIvsIT](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/kikivsit/32/10492_2.png) [@KIKIvsIT](https://forum.makecode.com/u/KIKIvsIT)\
**Post date:** [November 27, 2020, 3:51am UTC](https://forum.makecode.com/t/am-i-missing-something/4659/3 "2020-11-27T03:51:46Z")

</div>

It works in JavaScript…

> **[Test](https://makecode.microbit.org/03916-23057-79688-13480)**
>
> Made with ❤️ in Microsoft MakeCode for micro:bit.

---

<div class="post-metadata">

**Author:** ![charliegregg](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/charliegregg/32/2411_2.png) [@charliegregg](https://forum.makecode.com/u/charliegregg)\
**Post date:** [November 27, 2020, 4:35am UTC](https://forum.makecode.com/t/am-i-missing-something/4659/4 "2020-11-27T04:35:01Z")

</div>

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  
test[1]  
returns an error  
can this be fixed?

---

<div class="post-metadata">

**Author:** ![KIKIvsIT](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/kikivsit/32/10492_2.png) [@KIKIvsIT](https://forum.makecode.com/u/KIKIvsIT)\
**Post date:** [November 29, 2020, 12:03am UTC](https://forum.makecode.com/t/am-i-missing-something/4659/5 "2020-11-29T00:03:22Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![RishabhSheoran](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/rishabhsheoran/32/5996_2.png) [@RishabhSheoran](https://forum.makecode.com/u/RishabhSheoran)\
**Post date:** [March 25, 2022, 8:04pm UTC](https://forum.makecode.com/t/am-i-missing-something/4659/6 "2022-03-25T20:04:20Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![bsiever](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/bsiever/32/1032_2.png) [@bsiever](https://forum.makecode.com/u/bsiever)\
**Post date:** [March 28, 2022, 3:05pm UTC](https://forum.makecode.com/t/am-i-missing-something/4659/7 "2022-03-28T15:05:26Z")

</div>

I don’t think Python currently supports `split()` on strings. I’ve opened an “issue” on GitHub to report the error. See here: [https://github.com/microsoft/pxt/issues/8752](https://github.com/microsoft/pxt/issues/8752)

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):

```auto
words = "this is a test"

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

splitBySpace = simpleSplit(words, " ")
serial.write_number(len(splitBySpace))
serial.write_line("")
for w in splitBySpace:
    serial.write_line(w)

```

---

<div class="post-metadata">

**Author:** ![bsiever](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/bsiever/32/1032_2.png) [@bsiever](https://forum.makecode.com/u/bsiever)\
**Post date:** [July 29, 2022, 4:28pm UTC](https://forum.makecode.com/t/am-i-missing-something/4659/8 "2022-07-29T16:28:29Z")

</div>

The GitHub issue has been closed. It looks like `split()` in Python may now work: [https://github.com/microsoft/pxt/issues/8752#issuecomment-1198700037](https://github.com/microsoft/pxt/issues/8752#issuecomment-1198700037) .
