python 3 IRC 机器人语法错误
好吧,首先。我对 python 很陌生,我刚刚开始自学 python 3 作为一个帮助我学习的有趣项目,我决定做一个 IRC 机器人,我想我将遵循创建基本机器人的基本教程,当我学习时,我可以向它添加更多内容,并使其成为我自己的,但问题是我相信 本教程是为 python 2.x 编写的。我遇到了一些我可以自己修复的错误,但现在我遇到了这个我似乎无法弄清楚的语法错误。 错误位于第 39 行,这里是第 38 行和第 39 行(38 是因为我在那里有一个语法错误,但设法修复它)
if msgpart[0]=='`' and sender[0]==OWNER # Treat all messages start with ` as a command
cmd=msgpart[1:].split('')
,我得到的错误是。
File "pybot.py", line 39
cmd=msgpart[1:].split('')
^
Syntax error: invalid syntax
第 38 行的错误是同样的事情,但我删除了所有者之后的 : 并修复了 本身,这对我来说很奇怪,因为根据我的理解,应该是 : 在 IF 语句之后。
Okay, first off. I'm very new to python, and I've just started to teach myself python 3
As a fun project to help me learn I decieded to do an IRC Bot, I figured I'll follow a basic tutorial on creating a basic bot, and as I learn I could add more to it, and make it my own but the problem is I believe
the tutorial was written for python 2.x. I've gotten a few errors that I was able to fix on my own, but now I'm getting this syntax error that I cant seem to figure out.
the error is on line 39, here are lines 38 and 39, (38 because I had a syntax error there but managed to fix it)
if msgpart[0]=='`' and sender[0]==OWNER # Treat all messages start with ` as a command
cmd=msgpart[1:].split('')
and the error I get is.
File "pybot.py", line 39
cmd=msgpart[1:].split('')
^
Syntax error: invalid syntax
the error on line 38 was kind of the same thing, but with that I removed the : after owner and it fixed
itself, which seemed weird to me because from what I understand theres supposed to be : after IF statements.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您在
if
语句后缺少:
。应该是:You are missing
:
afterif
statement. Should be:if
语句末尾缺少冒号:
:应该是:
You are missing a colon
:
at the end of theif
statement:should be:
检查源文件中的制表符和空格是否一致。第39行前面似乎有3个空格(通常是4个,或者至少是偶数)。
像其他人所说的那样,在第 38 行加上冒号
:
。split('')
中的空字符串没有语法错误,但看起来也很奇怪。你想在那里实现什么目标?Check that your tabs and spaces are consistent in the source file. There seem to be 3 spaces in front of line 39 (normally it's 4, or at least some even number).
Plus the colon
:
at line 38 like others said.The empty string in
split('')
is no syntax error, but it also looks weird. What are you trying to achieve there?