【发布时间】:2021-08-13 23:21:02
【问题描述】:
班级无法理解的事情。
From aiogram.types import InputFile
a = InputFile(r'C:\Users\Acer\Desktop\f\1.mp3')
b = InputFile(r'C:\Users\Acer\Desktop\f\2.mp3')
c = InputFile(r'C:\Users\Acer\Desktop\f\3.mp3')
d = InputFile(r'C:\Users\Acer\Desktop\f\4.mp3')
e = InputFile(r'C:\Users\Acer\Desktop\f\5.mp3')
class Make:
def __init__(self, art, zanr, name, put):
self.art = art
self.zanr = zanr
self.name = name
self.put = put
a1 = Make('Blaze', 'Hip-hop', 'Music_1234', a)
b1 = Make('PORCHY', 'Rap', 'Trak_28', b)
c1 = Make('Blaze', 'Pop', 'North-abc', c)
d1 = Make('PORCHY', 'Hip-hop', '26-83', d)
e1 = Make('Blaze', 'Pop', 'Abnov', e)
spis = [a1, b1, c1, d1, e1]
for x in range(0, 4):
if spis[x].art == 'PORCHY':
print(cl.spis[x].put)
控制台:
<InputFile 'attach://GqEaqV-Wj3zekeFP9GIygA' with file='<_io.BufferedReader name='C:\\Users\\Acer\\Desktop\\f\\2.mp3'>'>
<InputFile 'attach://JeYgSuIUgVjS7nDwPONivQ' with file='<_io.BufferedReader name='C:\\Users\\Acer\\Desktop\\f\\4.mp3'>'>
为什么不呢:
C:\Users\Acer\Desktop\f\2.mp3
C:\Users\Acer\Desktop\f\4.mp3
【问题讨论】:
-
如果您指的是双反斜杠,这很可能是通过
BufferedReader.__repr__使用str.__repr__来生成文件名的表示的结果。跨度> -
不,为什么不直接返回变量“a”的值,格式为:C:\Users\Acer\Desktop\f\2.mp3。如何让它像这样返回?
-
因为
put属性是一个InputFile实例,而不仅仅是一个文件名。您必须查看InputFile的定义,才能了解为什么它的__str__方法(或者可能是__repr__方法)是这样定义的。 -
换句话说,它是显示变量
a的值;该值不是str对象。
标签: python class oop import python-class