python 3 IRC 机器人语法错误

发布于 2024-11-26 01:09:18 字数 599 浏览 0 评论 0原文

好吧,首先。我对 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

太阳哥哥 2024-12-03 01:09:18

您在 if 语句后缺少 : 。应该是:

if msgpart[0]=='`' and sender[0]==OWNER:
   cmd=msgpart[1:].split('')

You are missing : after if statement. Should be:

if msgpart[0]=='`' and sender[0]==OWNER:
   cmd=msgpart[1:].split('')
ˇ宁静的妩媚 2024-12-03 01:09:18

if 语句末尾缺少冒号 :

if msgpart[0]=='`' and sender[0]==OWNER  # Treat all messages start with ` as a command
                                       ^

应该是:

if msgpart[0]=='`' and sender[0]==OWNER:  # Treat all messages start with ` as a command
                                       ^

You are missing a colon : at the end of the if statement:

if msgpart[0]=='`' and sender[0]==OWNER  # Treat all messages start with ` as a command
                                       ^

should be:

if msgpart[0]=='`' and sender[0]==OWNER:  # Treat all messages start with ` as a command
                                       ^
花想c 2024-12-03 01:09:18

检查源文件中的制表符和空格是否一致。第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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文