小编Cod*_*key的帖子

如何安装discord.py重写?

我跑了,python3 -m pip install -U discord.py但它只安装了discord.py v0.16.x. 如何安装新的discord.py rewrite v1.0?

我卸载旧的discord.py使用pip uninstall discord.py并重新运行pip来安装discord.py,只是为了再次获得版本v0.16.x而不是新的v1.0版本.

python anaconda discord discord.py discord.py-rewrite

7
推荐指数
1
解决办法
2万
查看次数

Discord.py bot doesn't send keycap emojis

I tried creating a simple menu system and used reactions as buttons in a bot. Problem is, every time I tried to send an emoji (numeric digit emojis, one for each command in the menu), Discord spits out an error: unknown emoji. Here's the method I am using:

async def show_buttons(embed_object, menu, message):
    emojis = ['1??','2??','3??','4??','5??','6??','7??','8??','9??']
    human_user = message.author
    msg = await client.send_message(message.channel, embed=embed_object)
    for command, emoji in zip(game_engine.buttons[menu], emojis): 
        await client.add_reaction(msg, emoji)
    res = await client.wait_for_reaction(emojis, user=human_user, message=msg)
    await …
Run Code Online (Sandbox Code Playgroud)

python emoji discord.py

4
推荐指数
1
解决办法
603
查看次数

如何使用Scrapy在线解析PDF页面?

我尝试使用带有 PyPDF2 库的 Scrapy 在线抓取 PDf,但未成功。到目前为止,我能够浏览所有链接并能够获取 PDf 文件,但是通过 PyPDF2 提供它们似乎是一个问题。

注意:我的目标不是抓取/保存 PDF 文件,我打算通过首先将 PDF 转换为文本然后使用其他方法处理此文本来解析它们。

为简洁起见,我没有在此处包含完整代码。这是我的代码的一部分:

import io
import re
import PyPDF2
import scrapy
from scrapy.item import Item

class ArticleSpider(scrapy.Spider):
    name = "spyder_ARTICLE"                                                 
    start_urls = ['https://legion-216909.appspot.com/content.htm']                                                                      

    def parse(self, response):                                              
        for article_url in response.xpath('//div//a/@href').extract():      
            yield response.follow(article_url, callback=self.parse_pdf) 

    def parse_pdf(self, response):
        """ Peek inside PDF to check for targets.
        @return: PDF content as searcable plain-text string
        """
        reader = PyPDF2.PdfFileReader(response.body)
        text = u""

        # Title is optional, may be None
        if …
Run Code Online (Sandbox Code Playgroud)

python scrapy pypdf2

2
推荐指数
1
解决办法
1861
查看次数

如何将杂乱无章的字典扁平化为列表?

我试图压平一个杂乱无章的字典(这又是从一个 json 文件中提取的)以简化提取信息。下面是字典的结构示例以及我尝试将其展平的示例:

data = {'horse':{'speed':{"walk": 40, "run":50}}, 'dog':{'run':30}, 'human':{'gait':{'normal':{'run': 25, 'walk': 30}}}}

flat_dict = []
for items in list(data.items()):
    flat_list = []
    flat_list.append(items[0])
    try:
        for item in list(items[1].items())[0]:
            if type(item) is not dict: 
                flat_list.append(item)
            else:
                flat_list.append(list(item.keys())[0])
                flat_list.append(list(item.values())[0])
    except:
        flat_list.append(items[0])
    flat_dict.append(flat_list)

print(flat_dict)
Run Code Online (Sandbox Code Playgroud)

然而上面的代码并没有使整个字典变平并且丢失了一些信息,下面是上面代码的输出:

[['horse', 'speed', 'walk', 40], ['dog', 'run', 30], ['human', 'gait', 'normal', {'run': 25, 'walk': 30}]]
Run Code Online (Sandbox Code Playgroud)

我想要的是:

[['horse', 'speed', 'walk', 40, 'run', 50], ['dog', 'run', 30], ['human', 'gait', 'normal', 'run', 25, 'walk', 30]]
Run Code Online (Sandbox Code Playgroud)

我该怎么办?

python dictionary list

2
推荐指数
1
解决办法
91
查看次数