简体   繁体   English

为什么我得到错误'str' object has no attribute 'head'?

[英]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.

相关问题 为什么我在这里收到错误消息“'str'对象没有属性'str'”,'occurred at index 0'” - why do I get the error message "'str' object has no attribute 'str'", 'occurred at index 0'" here 为什么我有 ''str' object has no attribute 'copy'' 错误? - Why do i have ''str' object has no attribute 'copy'' error? 为什么我在这个python代码中得到一个“AttributeError:'str'对象没有属性'write'” - Why do I get an “AttributeError: 'str' object has no attribute 'write' ” in this python code 为什么会出现“对象没有属性‘排除’”错误? - Why do I get "object has no attribute 'exclude'" error? 收到此错误“str”object 没有属性“get” - getting this error 'str' object has no attribute 'get' 属性错误:“str”object 没有属性“str” - Attribute Error: 'str' object has no attribute 'str' 尝试引用pandas df列中的特定单元格时,为什么会出现“ AttributeError:'str'对象没有属性'iloc”的问题? - Why do I get “AttributeError: 'str' object has no attribute 'iloc” when trying to reference a specific cell in a pandas df column? 为什么会出现“属性错误:'int'对象没有属性'lower'”? - why do i get “Attribute Error: 'int' object has no attribute 'lower'”? 'str' object has no attribute 'get' attribute error in django - 'str' object has no attribute 'get' attribute error in django str object 没有属性 get - str object has no attribute get
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM