尝试打印多行字符串时出错

Error when trying to print string with multiple lines

我正在尝试在 Python 中制作井字游戏,但每当我尝试打印棋盘时,我都会收到一个奇怪的错误。这是我的代码:

import os
from colorama import Fore


board = "   a     b     c\n     |     |     \n1  -  |  -  |  -  \n  _____|_____|_____\n      |     |     \n2  -  |  -  |  -  \n _____|_____|_____\n      |     |     \n3  -  |  -  |  -  \n      |     |    "

def board():
  print(board)

board()

这是错误:

 SIGQUIT: quit
PC=0x7f1a62b22792 m=0 sigcode=128
signal arrived during cgo execution

goroutine 1 [syscall, locked to thread]:
runtime.cgocall(0x4bb660, 0xc000066d90)
    runtime/cgocall.go:156 +0x5c fp=0xc000066d68 sp=0xc000066d30 pc=0x40651c
main._Cfunc_PyRun_InteractiveLoopFlags(0x7f1a62be9800, 0x55555691b800, 0x0)
    _cgo_gotypes.go:418 +0x4c fp=0xc000066d90 sp=0xc000066d68 pc=0x4b8e4c
main.Python.REPL.func2(0x55555691b800)
    github.com/replit/prybar/languages/python3/main.go:122 +0x66 fp=0xc000066dd0 sp=0xc000066d90 pc=0x4bacc6
main.Python.REPL({})
    github.com/replit/prybar/languages/python3/main.go:122 +0x99 fp=0xc000066e10 sp=0xc000066dd0 pc=0x4bac19
main.(*Python).REPL(0x5d56d0)
    <autogenerated>:1 +0x2a fp=0xc000066e20 sp=0xc000066e10 pc=0x4bb36a
github.com/replit/prybar/utils.Language.REPL({{0x5075d0, 0x5d56d0}, {0x7ffd00c3ac79, 0x4e1680}})
    github.com/replit/prybar/utils/language.go:100 +0x5d fp=0xc000066e78 sp=0xc000066e20 pc=0x4b825d
github.com/replit/prybar/utils.DoCli({0x5075d0, 0x5d56d0})
    github.com/replit/prybar/utils/utils.go:77 +0x3d7 fp=0xc000066f60 sp=0xc000066e78 pc=0x4b8a97
main.main()
    github.com/replit/prybar/languages/python3/generated_launch.go:7 +0x27 fp=0xc000066f80 sp=0xc000066f60 pc=0x4b8bc7
<function board at 0x7f5f840e2280>

我以前从未见过这样的错误,我想知道它是什么意思以及如何解决它?感谢您的帮助!

问题是您将所有内容命名为“board”

当您在“board = ...”之后执行“def board()”时,您正在将 board 重新定义为一个函数,而不再是一个字符串。

您遇到的错误是因为您的编辑器不支持打印功能