python - 课堂上无法理解的东西
问题描述
课堂上有些难以理解的东西。
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
解决方案
通过查看InputFile 源代码,您可以看到该__str__
方法的定义如下:
def __str__(self):
return f"<InputFile 'attach://{self.attachment_key}' with file='{self.file}'>"
并且__repr__
方法等于__str__
。
如果您只想打印文件的路径,我相信您应该使用
print(cl.spis[x].put.get_filename())
推荐阅读
- c++ - 使用 Cmake 构建 PCL 教程时如何处理“未设置策略 CMP0074”错误?
- azure-storage - Azure 文件存储服务器以 400 状态响应(不支持条件标头。)
- react-native - 需要firebase图像存储路径,但 storageRef 正在返回一个承诺 - 反应原生
- go - Web 服务器正常关闭未按预期工作
- java - JList 选择随机跳转到上一个索引
- junit - 如何模拟 xyz.capybara.clamav.commands.scan.result.ScanResult getStatus 方法
- r - R mlogit 包:使用 LAPACK 而不是 LINPACK
- php - 显示网页上所有链接的 PHP 代码
- swift - 如何自定义 UITableView 的标题背景颜色、高度和文本?
- c# - C# - How to Determine if a Configuration Section exists in a mapped EXE configuration file?