如何只打印文件的特定部分

How to print only a specific part of a file

所以我有一个名字列表,例如:

XX1
XX2
XX3
XZ1
XZ2 

按品牌划分,如:

Atlas

    XX1
    XX2
    XX3

Tediore

    XZ1
    XZ2

在此之后我只想打印用户选择的请求品牌的特定武器:

elif text.startswith('/weapon'):
    keyboard = InlineKeyboardMarkup(inline_keyboard =[[InlineKeyboardButton(text='Atlas', callback_data='Atlas')],
                                                      [InlineKeyboardButton(text='Tediore', callback_data='tediore')],
                                                      [InlineKeyboardButton(text='DAHL', callback_data='DAHL')],])
bot.sendMessage(msg_data['chat_id'],"Select the brand ?",reply_markup = keyboard )

有什么想法吗?

我不完全确定您要拍摄什么,但您可以使用嵌套字典策略,其中品牌是第一级的关键字,而 'weapon' 等标签是第二级。例如

myBrands={'brand1':{'weapon':brandOneWeapon}}

这样当您调用 myBrands 时,您可以使用按键只获取您想要的内容。

currentWeapon=myBrands['brand1']['weapon']
print(currentWeapon)