# Problem mit split Funktion in Python

**URL:** <https://forum.calliope.cc/t/problem-mit-split-funktion-in-python/1945>\
**Category:** Fragen zu MakeCode/PXT\
**Created:** [24. Januar 2021 um 11:37 UTC](https://forum.calliope.cc/t/problem-mit-split-funktion-in-python/1945 "2021-01-24T11:37:47Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![AlexandreM](https://avatars.discourse-cdn.com/v4/letter/a/ecccb3/32.png) [@AlexandreM](https://forum.calliope.cc/u/AlexandreM)\
**Post date:** [24. Januar 2021 um 11:37 UTC](https://forum.calliope.cc/t/problem-mit-split-funktion-in-python/1945/1 "2021-01-24T11:37:47Z")

</div>

Hallo,  
Ich möchte ein Musik-Programm auf dem Calliope-mini programmieren

Ich habe ein String mit meine Noten, den ich in ein Array umwandeln möchte.  
Dann diese Array kann in der Funktion „music.start\_melody“ verstanden werden.

Hier ist mein Code :

```
# Input string melody
stringMusic = "B:3,D:4,CSHARP:3"
print("String : " + stringMusic)

arrayMusic = stringMusic.split(",")
print("Array : " + arrayMusic)
print("Array element 0 : " + arrayMusic[0])

# Output wanted ["B:3", "D:4", "CSHARP:3"]

```

Hier ist das Simulator console :

```
String : B:3,D:4,CS:3
Array : [object Object]
Array element 0 : undefined

```

In diesem Kontext, die „split“ Funktion gibt „undefined“ zurück und nicht das Array  
Ich glaube ich habe keine Fehler in Python gemacht

Habt ihr schon einmal diese Problem gehabt?

Vielen Dank  
Alexandre

PS : Ich lerne noch Deutsch, ich hoffe ihr versteht mir 🙂

---

<div class="post-metadata">

**Author:** ![ToniTaste](https://avatars.discourse-cdn.com/v4/letter/t/53a042/32.png) [@ToniTaste](https://forum.calliope.cc/u/ToniTaste)\
**Post date:** [24. Januar 2021 um 12:40 UTC](https://forum.calliope.cc/t/problem-mit-split-funktion-in-python/1945/2 "2021-01-24T12:40:31Z")

</div>

Hallo AlexandreM,

folgendes funktioniert bei mir:

```
feld: List[str] = []
stringMusic = "B:3,D:4,CSHARP:3"
feld = stringMusic.split(",")
Index = 0
while Index <= len(feld):
    music.play_tone(262, music.beat(BeatFraction.SIXTEENTH))
    basic.show_string("" + (feld[Index]))
    basic.pause(2000)
    Index += 1

```

oder mit Blöcken:

 ![mini-Screenshot](https://canada1.discourse-cdn.com/flex027/uploads/calliope/original/2X/9/96c7042b1a02c3abdf5d83a666a8d4b4e6c1c9a7.png)

Die Schleife untern dient nur der Ausgabe. Verzichte ich in deinem Quelltext auf print, klappt es auch.

HG Toni

---

<div class="post-metadata">

**Author:** ![AlexandreM](https://avatars.discourse-cdn.com/v4/letter/a/ecccb3/32.png) [@AlexandreM](https://forum.calliope.cc/u/AlexandreM)\
**Post date:** [25. Januar 2021 um 10:12 UTC](https://forum.calliope.cc/t/problem-mit-split-funktion-in-python/1945/3 "2021-01-25T10:12:19Z")

</div>

Hallo Toni,  
Danke für deine Antwort! 🙂

Ich habe deine Python code auf meine code kopiert, aber das funktioniert nicht… („undefined“ rührkehrt). Normalerweise ich codiert im Python direkt und ich nicht der Blöcken verwenden

So habe ich deine Blöcke in ein neues Projekt kopiert, und das funktioniert, aber wenn ich den Python code direkt in ein neues Projekt kopiere, das funktioniert nicht…  
Ich habe auch an eine Calliope Mini REV2 (letzte bootloader) getestet, gleiches Verhalten…

Villeicht gibt es eine code Umwandlung zwichen Python und Typescript (JavaScript) problem? Manchmal habe ich kleine Problem mit Variable setzen wenn ich mit Python programmiere…

Vielen Dank  
Alexandre

---

<div class="post-metadata">

**Author:** ![ToniTaste](https://avatars.discourse-cdn.com/v4/letter/t/53a042/32.png) [@ToniTaste](https://forum.calliope.cc/u/ToniTaste)\
**Post date:** [25. Januar 2021 um 11:21 UTC](https://forum.calliope.cc/t/problem-mit-split-funktion-in-python/1945/4 "2021-01-25T11:21:19Z")

</div>

Hallo Alexandre,

ich kann den Fehler replizieren. Er entsteht auch im Microbit-Editor. Leider kann ich da nicht helfen. Meine Python-Kenntnisse sind sehr oberflächlich.

Toni
