小编Sam*_*ett的帖子

我如何在discord.py中提及使用用户ID的用户

我正在尝试使用discord.py编写一个简单的机器人,所以我开始使用有趣的命令,就像获取api的挂起

import discord
import asyncio
client = discord.Client()


@client.event
async def on_message(message):
    # we do not want the bot to reply to itself
    if message.author == client.user:
        return

    if message.content.startswith('!hug'):
        await client.send_message(message.channel, "hugs {0.author.mention}".format(message))

    # Greetings
    if message.content.startswith('hello'):
        msg = 'Hello {0.author.mention}'.format(message)
        await client.send_message(message.channel, msg)        

    # say (id) is the best
    # This is where I am lost. how to mention someone's name or id ?
    if message.content.startswith('!best'):
        mid = User.id('ZERO#6885').format(message)
        await client.send_message(message.channel, '{mid} mentioned')
Run Code Online (Sandbox Code Playgroud)

python discord.py

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

枚举 _missing_ 函数不会消除 ValueError

我正在尝试设置一个枚举,None如果找不到该值,它将返回。该文档提到了一个 function _missing_,但没有解释有关该函数的任何细节:

\n\n
\n

_missing_\xe2\x80\x93 未找到值时使用的查找函数;可能会被覆盖

\n
\n\n

环顾四周后,这似乎是classmethod带有签名的cls, value,所以我尝试设置它,但它不起作用。

\n\n
>>> class G(enum.Enum):\n...   @classmethod\n...   def _missing_(cls, value):\n...     return None\n...   a = 1\n...\n>>> G(1)\n<G.a: 1>\n>>> G(2)\nTraceback (most recent call last):\n  ...\nValueError: 2 is not a valid G\n>>> G[\'b\']\nKeyError: \'b\'\n>>> G.b\nAttributeError: b\n
Run Code Online (Sandbox Code Playgroud)\n\n

谷歌搜索表明_missing_仅捕获调用情况中的 ValueError ,因此 KeyError 和 TypeError 并不让我感到惊讶,但我不知道为什么G(2)会引发 ValueError 而不是返回None

\n

python enums python-3.x

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

指示参数应该是可变引用

使用 PEP 484 和 585 中指定的类型提示语法,有什么方法可以表明函数的参数应该是由函数修改的可变引用?

例如,C# 有ref参数,那么在 Python 中,是否有任何等价物?例如

>>> def foo(spam: "Mutable[List[int]]"):
...     spam.append(sum(spam))
...
>>> a = [1, 2, 3]
>>> foo(a)
>>> a
[1, 2, 3, 6]
Run Code Online (Sandbox Code Playgroud)

或者如果不是,我怎么能定义这样的类型而不导致检查逻辑认为它是一个特殊的Mutable类而不是一个List[int]?显然,这将用作开发人员更容易理解方法的工具,而不是用于从根本上更改程序的方法。

为了清楚起见,我知道,根据定义列表是可变的,但我不知道是否有一种方法来定义时,它会突变,例如

>>> def bar(sandwich: Mutable[List[str]], fridge: List[str]):
...     sandwich.extend(random.sample(fridge, k=3))
Run Code Online (Sandbox Code Playgroud)

python type-hinting python-3.x

5
推荐指数
1
解决办法
87
查看次数

如何从手动分区的BigQuery表中引用最新表

我们有一个手动分区的“视频元数据”表,每天都会收到新数据。在我们的系统中,旧数据仅出于历史原因保留,因为最新数据是最新的。

我们不能确定的是如何使用LookML引用此表中的最新分区。

到目前为止,我们已经尝试将视图存储在BigQuery中。我们已经尝试以标准和旧版SQL的形式将简单的“获取最新分区”查询存储为视图,但尝试失败,并且经过一些搜索,这似乎是设计使然,即使错误消息指出“未找到数据集”而不是更相关的东西。

我们还尝试将过滤器内置到Looker中,但是在使事情真正起作用并且仅通过它返回最新数据方面遇到了麻烦。

任何帮助,将不胜感激。

sql google-bigquery looker

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