【发布时间】:2020-06-21 09:04:53
【问题描述】:
我正在尝试为 micro:bit 编写一个程序,它将文本显示为莫尔斯电码。我查看了多个网站和 Stack Overflow 帖子,寻找一种将字符串拆分为字符的方法。
例如
string = "hello"
到
chars = ["h","e","l","l","o"]
我尝试创建一个名为 array 的函数来执行此操作,但这不起作用。
然后我尝试了这个:
def getMessage():
file = open("file.txt", "r")
data = file.readlines()
file.close()
words = []
for line in data:
for word in line:
words.append(word)
return words
有什么想法吗?
【问题讨论】:
-
list("hello") == ['h', 'e', 'l', 'l', 'o']. -
这将如何运作?
-
在 ipython 控制台中尝试 list('hello')..
-
在普通 IDLE 下也能正常工作。
标签: python micropython text-segmentation bbc-microbit