Golly Python错误:奇怪的语法错误“list没有属性g”

2024-06-17 17:00:17 发布

您现在位置:Python中文网/ 问答频道 /正文

我在Golly的Scripts文件夹中有下面的一段代码,但是它返回了一个属性错误,我不知道为什么会发生*。你知道吗

如果你了解生命的游戏:它应该把感应线圈自动靠近一个选定的不稳定模式,但这只是一个原型。你知道吗

import golly as g
import random as r

coilsinp = g.getstring('Python list of induction coils to use?', '', 'Induction coils')
layerinp = g.getstring('Maximum number of induction coils inducting each other?')
mcoilinp = g.getstring('Maximum number of induction coils?')

if coilsinp == '':
   coillist = [g.parse('2o$2o!'), g.parse('bo$obo$bo!'), g.parse('b2o$o2bo$bobo$2bo!'). g.parse('b3o$o2bo$bobo$2bo!'). g.parse('3o$o2bo$b2o!'), g.parse('3o$o2bo$2b2o!')]
else:
   coillist = coilsinp.split(',')

if layerinp != '':
   maxlayers = layerinp
else:
   maxlayers = 3

if mcoilinp != '':
   maxcoils = mcoilinp
else:
   maxcoils = 12

dpa = (maxcoils - r.randint(0, maxcoils))
tosel = g.getcells(g.getselrect)
dasel = g.getselrect
g.addlayer()
g.putcells(tosel, 0, 0)
g.select(0, 0, dasel[2], dasel[3])
while true:

   while dpa > 0:
      g.putcells(coilsinp[r.randint(0, 5)], r.randint(-11, (dasel[2] + 11), r.randint(-11, (dasel[3] + 11))
      dpa -= 1

   if g.getselrect == g.evolve(g.getcells(g.getselrect), 50):
      break

回溯到第9行。你知道吗

在编辑的时候,我已经发现了。我只是澄清一下主题是什么。你知道吗


Tags: ofifparseelserandintinductiongetstringcoils
1条回答
网友
1楼 · 发布于 2024-06-17 17:00:17

查看第3、第4和第5行列表元素之间的源代码第9行。您用句点而不是逗号分隔,从而得到一个长的

g.parse('b2o$o2bo$bobo$2bo!'). g.parse('b3o$o2bo$bobo$2bo!'). g.parse('3o$o2bo$b2o!')

解析器在g.parse('b2o$o2bo$bobo$2bo!'). g处出错,因为解析器的返回没有任何名为“g”的属性(括号后面的属性)。你知道吗

这能让你动起来吗?你知道吗

相关问题 更多 >