AttributeError: 'Images' object has no attribute 'pop'
AttributeError: 'Images' object has no attribute 'pop'
我正在使用这段代码,所以我的主要代码在这里:
from draw_image import Images
start = Images()
start.display_image()
start.delete_line()
start.display_image()
这是我的 draw_image 代码:
class Images:
def image(jumper_image):
"""This function is to create the list"""
jumper_image = []
def display_image(jumper_image):
"""This is how the user will see the image correctly through the loop"""
jumper_image = [
" ___ ",
" /___\ ",
" \ / ",
" \ / ",
" o ",
" /|\ ",
" / \ ",
" ",
"^^^^^^^^^^^"
]
for image in jumper_image:
print(image)
return jumper_image
def delete_line(jumper_image):
""" This function is supposed to delete the first line of the jumper_image"""
jumper_image.pop(0)
似乎 delete_line 功能无法识别列表,你们知道为什么会这样吗?或者这个问题的解决方案是什么?
我建议使用 python 构造函数来初始化 jumper_image
:
class Images:
def __init__(self):
self.jumper_image = [
" ___ ",
" /___\ ",
" \ / ",
" \ / ",
" o ",
" /|\ ",
" / \ ",
" ",
"^^^^^^^^^^^"
]
def display_image(self):
"""This is how the user will see the image correctly through the loop"""
for image in self.jumper_image:
print(image)
def delete_line(self):
""" This function is supposed to delete the first line of the jumper_image"""
self.jumper_image.pop(0)
start = Images()
start.display_image()
start.delete_line()
print('After deleting first value in list\n')
start.display_image()
___
/___\
\ /
\ /
o
/|\
/ \
^^^^^^^^^^^
After deleting first value in list
/___\
\ /
\ /
o
/|\
/ \
^^^^^^^^^^^
我正在使用这段代码,所以我的主要代码在这里:
from draw_image import Images
start = Images()
start.display_image()
start.delete_line()
start.display_image()
这是我的 draw_image 代码:
class Images:
def image(jumper_image):
"""This function is to create the list"""
jumper_image = []
def display_image(jumper_image):
"""This is how the user will see the image correctly through the loop"""
jumper_image = [
" ___ ",
" /___\ ",
" \ / ",
" \ / ",
" o ",
" /|\ ",
" / \ ",
" ",
"^^^^^^^^^^^"
]
for image in jumper_image:
print(image)
return jumper_image
def delete_line(jumper_image):
""" This function is supposed to delete the first line of the jumper_image"""
jumper_image.pop(0)
似乎 delete_line 功能无法识别列表,你们知道为什么会这样吗?或者这个问题的解决方案是什么?
我建议使用 python 构造函数来初始化 jumper_image
:
class Images:
def __init__(self):
self.jumper_image = [
" ___ ",
" /___\ ",
" \ / ",
" \ / ",
" o ",
" /|\ ",
" / \ ",
" ",
"^^^^^^^^^^^"
]
def display_image(self):
"""This is how the user will see the image correctly through the loop"""
for image in self.jumper_image:
print(image)
def delete_line(self):
""" This function is supposed to delete the first line of the jumper_image"""
self.jumper_image.pop(0)
start = Images()
start.display_image()
start.delete_line()
print('After deleting first value in list\n')
start.display_image()
___
/___\
\ /
\ /
o
/|\
/ \
^^^^^^^^^^^
After deleting first value in list
/___\
\ /
\ /
o
/|\
/ \
^^^^^^^^^^^