我正在尝试创建一个当前仅包含以下内容的动态函数:
"chosen = random.choice([<ClassLibrary.Field object at 0x0330FA48> , <ClassLibrary.Field object at 0x0330FAA8> , <ClassLibrary.Field object at 0x0330FB08> , <ClassLibrary.Field object at 0x0330FB98> , <ClassLibrary.Field object at 0x0330FC28> , <ClassLibrary.Field object at 0x0330FCB8> , <ClassLibrary.Field object at 0x0330FD48> , <ClassLibrary.Field object at 0x0330FDD8> , <ClassLibrary.Field object at 0x0330FE68>])"
这意味着我有一个变量设置为等于列表中的随机元素。但是我得到了一个语法错误,大概是因为列表对象是对这些对象在内存中的空间的引用?choice() 与原始列表一起使用,如下所示:
chosen = random.choice(ticTacToe.fields)
我得到的错误是:
File "C:\Users\churc\Documents\P7\P7 Modular Playtesting\ticTacToe2.py", line 267, in <module>
eval(FunctionLibrary.makeExecutableStatement(ticTacToe.players[1].actions[0].statements[0]))
File "<string>", line 1
chosen = random.choice([<ClassLibrary.Field object at 0x0330FA48> , <ClassLibrary.Field object at 0x0330FAA8> , <ClassLibrary.Field object at 0x0330FB08> , <ClassLibrary.Field object at 0x0330FB98> , <ClassLibrary.Field object at 0x0330FC28> , <ClassLibrary.Field object at 0x0330FCB8> , <ClassLibrary.Field object at 0x0330FD48> , <ClassLibrary.Field object at 0x0330FDD8> , <ClassLibrary.Field object at 0x0330FE68>])
^
SyntaxError: invalid syntax
[Finished in 0.1s with exit code 1]
有人知道我在做什么错吗?以及如何纠正?