小编Aet*_*tos的帖子

Java泛型,未绑定的通配符<?> vs <Object>

我已经阅读了一些主题,其中涵盖了关于泛型的某些问题,例如它们与原始类型关系.但是我想对Java SE教程中关于未绑定泛型的某一行进行补充说明.

根据一句话:

printList的目标是打印任何类型的列表,但它无法实现该目标 - 它只打印一个Object实例列表; 它不能打印List <Integer>,List <String>,List <Double>等,因为它们不是List <Object>的子类型.

如果我理解这句话; 之间的区别List<?>List<Object>,就是我们可以使用的类型参数List<String>List<Integer>通过实施前.如果我们实现后者,我们只能使用type参数List<Object>.好像List<?>是一个上界ObjectList<? Object>.

但是后面的句子让我感到困惑,因为根据我之前的理解,它List<Object>应该只包含类的实例Object而不包含其他内容.

重要的是要注意List<Object>并且List<?>不一样.您可以将Object或Object的任何子类型插入到List<Object>.但是你只能插入null一个List<?>.

java generics wildcard

13
推荐指数
2
解决办法
4302
查看次数

在没有 sudo 的情况下使用 docker-compose 不起作用

最近有人告诉我,运行dockerdocker-compose使用 sudo 是一个大问题,我必须创建/将我的用户添加到docker组中才能在docker没有 . 我按照这里的文档做了docker-composesudo

现在,docker通过我的用户正常运行。例如:

~$ docker run hello-world

Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
b8dfde127a29: Pull complete
Digest: sha256:df5f5184104426b65967e016ff2ac0bfcd44ad7899ca3bbcf8e44e4461491a9e
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled …
Run Code Online (Sandbox Code Playgroud)

linux ubuntu root docker docker-compose

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

尝试使用“gcloud init”进行身份验证时出错

我正在尝试使用以下方式验证 gcloud sdk gcloud init:。

我得到了一个应该访问的 URL,以便复制令牌并将其返回到 CLI...但我得到的不是令牌,而是以下错误:

Erreur d'autorisation
Erreur 400 : invalid_request
Missing required parameter: redirect_uri
Run Code Online (Sandbox Code Playgroud)

这是一个错误吗?

gcloud version信息:

Google Cloud SDK 377.0.0
alpha 2022.03.10
beta 2022.03.10
bq 2.0.74
bundled-python3-unix 3.8.11
core 2022.03.10
gsutil 5.8
Run Code Online (Sandbox Code Playgroud)

gcloud init我在 wsl2 (Ubuntu 18.04) 上运行。安装 gcloud 后立即出现此错误sudo apt install google-cloud-sdk

oauth-2.0 google-cloud-platform gcloud windows-subsystem-for-linux wsl-2

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

对 Airflow 的 BaseSensorOperator 参数感到困惑:超时、poke_interval 和模式

我对BaseSensorOperator参数的工作方式有点困惑:timeout & poke_interval。考虑传感器的这种用法:

BaseSensorOperator(
  soft_fail=True,
  poke_interval = 4*60*60,  # Poke every 4 hours
  timeout = 12*60*60,  # Timeout after 12 hours
)
Run Code Online (Sandbox Code Playgroud)

文档提到超时行为在任务用完后将任务设置为“失败”。但是我使用的是soft_fail=True,我认为它不会保留相同的行为,因为我发现任务失败而不是在我同时使用参数soft_failtimeout.

那么这里发生了什么?

  1. 传感器每4小时戳一次,每戳一次,是否会等待超时时间(12小时)?
  2. 还是每 4 小时戳一次,总共戳 3 次,然后超时?
  3. 另外,如果我使用 mode="reschedule",这些参数会发生什么?

这是 BaseSensorOperator 的文档

class BaseSensorOperator(BaseOperator, SkipMixin):
    """
    Sensor operators are derived from this class and inherit these attributes.
    Sensor operators keep executing at a time interval and succeed when
    a criteria is met and fail if and when …
Run Code Online (Sandbox Code Playgroud)

airflow google-cloud-composer

6
推荐指数
2
解决办法
2882
查看次数

在我编写的函数中使用pandas.read_csv文档字符串

我想用以下标头编写一个函数:

def split_csv(file, sep=";", output_path=".", nrows=None, chunksize=None, low_memory=True, usecols=None):
Run Code Online (Sandbox Code Playgroud)

如您所见,我使用的参数与中的几个参数相同pd.read_csv。我想知道(或要做)的是将与这些参数有关的文档字符串转发read_csv到我自己的函数中,而不必复制/粘贴它们。

编辑:据我了解,没有开箱即用的现有解决方案。因此,也许要按顺序建造一个。我的想法:

some_new_fancy_library.get_doc(for_function = pandas.read_csv,for_parameters = ['sep','nrows']) 将输出:

{'sep': 'doc as found in the docstring', 'nrows' : 'doc as found in the docstring', ...}

然后将字典的值插入到我自己的函数的文档字符串中就可以了

干杯

python documentation docstring pandas

5
推荐指数
0
解决办法
226
查看次数

难道“ a:1”不应该是python中的语法错误吗?

我在代码中打了一个错字,在语法上完全沉默了。

dict_args : {"arg1":1,"arg2":2,"arg3":3}
# .... Some more code
some_function(**dict_args)
# .... Some more code
Run Code Online (Sandbox Code Playgroud)

如果您没有注意到它,则在声明变量时使用:代替。=dict_args

所以我的问题是,莫非是Python语法:a:1本身,持有任何意义?还是假设它被认为是语法错误?

python syntax syntax-error python-3.x

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

无法从云存储发生更改时触发的云功能触发composer/airflow dag

google-cloud-composer我已经在环境(dlkpipelinesv1 :composer-1.13.0-airflow-1.10.12)上创建并运行了 dags 。我可以手动触发这些 dag,并使用调度程序,但是当我通过cloud-functions检测存储桶中的更改来触发它们时,我陷入了困境google-cloud-storage

请注意,我有另一个 GC-Composer 环境(管道:composer-1.7.5-airflow-1.10.2),它使用相同的谷歌云功能来触发相关的 dags,并且它正在工作

我按照本指南创建了触发 dags 的函数。所以我检索了以下变量:

PROJECT_ID = <project_id>
CLIENT_ID = <client_id_retrieved_by_running_the_code_in_the_guide_within_my_gcp_console>
WEBSERVER_ID = <airflow_webserver_id>
DAG_NAME = <dag_to_trigger>
WEBSERVER_URL = f"https://{WEBSERVER_ID}.appspot.com/api/experimental/dags/{DAG_NAME}/dag_runs"


def file_listener(event, context):
    """Entry point of the cloud function: Triggered by a change to a Cloud Storage bucket.
    Args:
         event (dict): Event payload.
         context (google.cloud.functions.Context): Metadata for the event.
    """
    logging.info("Running the file listener process")
    logging.info(f"event : {event}")
    logging.info(f"context : {context}") …
Run Code Online (Sandbox Code Playgroud)

python oauth google-oauth google-cloud-platform google-cloud-composer

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

How to describe an object type variable in Terraform?

I am trying to write a clear documentation/description of my terraform modules. According to Hashicorp's doc, the description attribute will permit that, but I cannot find a way to describe an object type variable in details.

Here's more or less I want to do :

variable "sa_to_impersonate_info" {
  type = object(
    {
      id                   = string
      email                = string
      belonging_org_id     = string
      belonging_project_id = string
      token_scopes         = list(string)
      token_lifetime       = string
    }
  )
  description = {
    id : "an identifier …
Run Code Online (Sandbox Code Playgroud)

terraform

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

哪种方法更适合计算迭代器的长度?

len(list(iterator))和 和有sum(1 for _ in iterator)什么区别?随后,哪个是用于计算迭代器长度的最佳方法?

python iterator python-3.x

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

在python中捕获异常...但仍然继续

tl; dr我使用,try: ... except Exception as err: pass但引发异常时代码仍然停止,即使不应该这样。

我正在csv上运行转换算法。转换之一考虑了数据库中列值的存在。如果它不存在,我将引发如下异常:

2019-05-15 16:36:37,095 - root - WARNING - The data in 'section_code' either doesn't exist in the raw data or hasn't been correctly encoded. The following strings caused the encoding error : '['398', 'die']'

我知道使用的这种做法不好try: ... except: pass,但是我希望我的代码继续转换文件,同时只记录错误/警告出现的位置。

这是将我的代码包含在try...except块中的方式

if __name__ == "__main__":
    try:
        # Initiate logger
        logging.basicConfig(
            level="DEBUG",
            format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')

        # Business code ...

    except FileNotFoundError as f_err:
        logging.exception(f_err) …
Run Code Online (Sandbox Code Playgroud)

python logging exception

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