首先,这是我的代码:
class Enemy():
def __init__(self, name, hp, damage):
self.name = name
self.hp = hp
self.damage = damage
def is_alive(self):
"""Checks if alive"""
return self.hp > 0
class WildBoar(Enemy):
def __init__(self):
super(WildBoar, name="Wild Boar", hp=10, damage=2).__init__()
class Marauder(Enemy):
def __init__(self):
super(Marauder, name="Marauder", hp=20, damage=5).__init__()
class Kidnappers(Enemy):
def __init__(self):
super(Kidnappers, name="The Kidnappers", hp=30, damage=7).__init__()
Run Code Online (Sandbox Code Playgroud)
当我编译这个时,我收到此错误:
super(WildBoar, name="Wild Boar", hp=10, damage=2).__init__()
TypeError: super does not take keyword arguments
Run Code Online (Sandbox Code Playgroud)
我试着寻找任何帮助,但我找不到任何东西.我也有一些Kwargs在其他类的超级,但这些是提出任何类型的问题(截至目前).那可能是什么导致了这个?我也看到有人说super在基类中放置一个将修复它,但它不起作用(我传入了Base类中的相同参数__init__).
我已经有这个问题了一段时间,我一直在不断寻找答案,最后选择在这里问一下.我见过的所有其他帖子都没有解决我的问题,我尝试过以下操作:
更改了快捷方式的绑定
确保在模板下检查
确保我的所有设置都正确无误
自动完成
当我输入syso并按下Ctrl + Space,而不是立即给我我想要的插入或快捷方式时,它只是打开"智能建议"菜单,我必须再次按Ctrl + Space才能进入"模板建议"菜单我实际上可以双击"'syso' - 打印到标准输出"然后它给了我全部System.out.println.它真的很混乱流量,非常烦人.
我的问题有什么问题吗?谢谢,
所以我正在阅读 Python 文档/教程,特别是我正在查看文件的输入/输出。这就是教程所说的将返回文件中的任何内容:
>>> f.readline()
'This is the first line of the file.\n'
>>> f.readline()
'Second line of the file\n'
>>> f.readline()
''
Run Code Online (Sandbox Code Playgroud)
我在 .py 中放入了同样的内容,它没有返回任何异常或问题,但它也没有返回任何值。这是我的代码:
f = open('test.txt')
f.readlines()
Run Code Online (Sandbox Code Playgroud)
除非我使用变量和 a print,否则程序将不会返回文件中的任何内容。这是我的文件内容:
Hello This Is Test
For Loops In Files
Flying Away
A Bird also Flies
Wow
Run Code Online (Sandbox Code Playgroud)
关于为什么这不起作用的任何想法?我认为它是我的解释器,因为我正在使用 SublimeREPL,但在此之前它没有做过任何奇怪的事情,所以我不太确定。另外,当我尝试在 Python 控制台中运行它时,它会给出一个错误,然后关闭控制台,这样我就看不到该错误了。相当适得其反。
只是为了澄清,我的问题不是for循环,for循环之前已经工作得很好。问题是f.readlines()不返回任何行,即使文档说它应该返回下一行。我将从for我的代码中取出循环来澄清。另外,很抱歉,如果我混淆了f.readline()和f.readlines(),但无论如何,它们都不起作用。
首先,让我告诉你我的代码:
import Tkinter
import tkMessageBox
import time
import sys
def endProgam():
raise SystemExit
sys.exit()
top = Tkinter.Tk()
B = Tkinter.Button(top, text = "Hello", command = endProgam)
B.pack()
top.mainloop()
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,endProgram()我尝试了两种类型的退出命令,两者都不起作用.我从来没有一起使用它们,我只是试图展示我到目前为止使用的方法.这些方法是我在这里和其他网站上找到的方法,但如果我尝试任何一种方法,我会收到此错误:
Traceback (most recent call last):
File "C:\Users\Sa'id\Documents\Learning Programming\Python\Tkinter Tuts.py", line 22, in <module>
top.mainloop()
File "C:\Python27\lib\lib-tk\Tkinter.py", line 1070, in mainloop
self.tk.mainloop(n)
File "C:\Python27\lib\lib-tk\Tkinter.py", line 1488, in __call__
raise SystemExit, msg
SystemExit
Run Code Online (Sandbox Code Playgroud)
我似乎无法找到解决方案,我希望也许有人可以帮助我.如果您需要更多细节,我很乐意为您提供所需.
python ×3
autocomplete ×1
button ×1
class ×1
eclipse ×1
exit ×1
file ×1
ide ×1
inheritance ×1
return ×1
return-value ×1
settings ×1
super ×1
text ×1
tk-toolkit ×1
tkinter ×1