[英]Why do I get the error 'str' object has no attribute 'head'?
I'm currently working on a module that makes, in short;我目前正在开发一个模块,简而言之; various text-based graphical interfaces for games.各种基于文本的游戏图形界面。
I have a class called 'interface' and in that class is a function 'comp' (short for computer) that makes a fake computer with fake directories that don't do anything我有一个名为“interface”的 class ,其中 class 是一个 function 'comp'(计算机的缩写),它可以制作带有不做假目录的假计算机
in 'comp' I have a variable called head that makes the border for the top part of the computer screen.在“comp”中,我有一个名为 head 的变量,它为计算机屏幕的顶部设置边框。
As I said before, it's text-based, so the border is a string.正如我之前所说,它是基于文本的,所以边框是一个字符串。 When I assign the character 'head' is going to use, I get this error:当我指定要使用的字符“头”时,我收到此错误:
File "C:\Users\Dell\Desktop\tub_rpg.py", line 14, in comp
self.head = head
AttributeError: 'str' object has no attribute 'head'
Does anybody know why this happens?有人知道为什么会这样吗? Here is 'comp':这是'comp':
def comp(self, head, headLeft, headRight, border, outer, user, folders, size):
self.head = head
self.headLeft = headLeft
self.headRight = headRight
self.border = border
self.outer = outer
self.user = user
and here is the file that uses the module, if that's of any help:这是使用该模块的文件,如果有帮助的话:
from tub_rpg import interface as tp
fakedirs = {"Media": ["Picture.jpg"], "Documents":["Profits.xls"], "Backup":["Profits-Copy.xls"], "Games":["DOOM.wad"]}
a,b,c,d,e,f,g, = "_", "[", "]", "[", "]", "ADMIN", 20
terminal = tp.comp(a, b, c, d, e, f, fakedirs, g, g)
i guess you want to do something like this as suggested by @Mark我想你想按照@Mark 的建议做这样的事情
class comp:
def __init__(self, head, headLeft, headRight, border, outer, user, folders, size):
self.head = head
self.headLeft = headLeft
self.headRight = headRight
self.border = border
self.outer = outer
self.user = user
def test(self):
print(self.head)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.