小编Geo*_*man的帖子

在python中,如果函数没有return语句,它返回什么?

鉴于此示例函数:

def writeFile(listLine,fileName):
    '''put a list of str-line into a file named fileName'''
    with open(fileName,'a',encoding = 'utf-8') as f:
        for line in listLine:
            f.writelines(line+'\r\n')
    return True
Run Code Online (Sandbox Code Playgroud)

这个return True陈述有用吗?

它和没有它有什么区别?如果没有返回功能会发生什么?

python python-3.x

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

你能在Swift字符串插值中使用字符串/字符文字吗?

是否可以在Swift中使用字符串插值中的字符串/字符文字?

语言参考说:

您在插值字符串中的括号内写的表达式不能包含未转义的双引号(")...

这对我来说有点模糊,因为它似乎故意留下了双重报价的漏洞.

如果我尝试:

println( "Output: \(repeat("H",20))" );

func repeat( char:Character, times:Int ) -> String {
    var output:String = "";
    for index in 1...times {
        output += char;
    }
    return output;
}
Run Code Online (Sandbox Code Playgroud)

我得到"预期","分隔符".

同样,如果我做同样的事情,但逃避报价,仍然没有骰子:

println( "Output: \(repeat(\"H\",20))" );
Run Code Online (Sandbox Code Playgroud)

我怀疑这是不可能的,说实话,没什么大不了的 - 我没有找到任何我不能通过在字符串插值之前做一点工作而轻易解决的例子,我想我只是在寻找确认这是不可能的.

swift

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

moto不嘲笑ec2?

我正在尝试测试一些使用boto的python代码.我宁愿不尝试对AWS进行集成测试,所以我试图用moto来模拟它,而且它的行为并不像我期望的那样.

这是测试代码:

import io
import boto3

from moto import mock_ec2
from unittest.mock import patch
from argparse import Namespace
from awswl import commands


@mock_ec2
@patch('awswl.externalip.get_external_ip', return_value='192.0.2.1')
def test_list_command_lists_ipv4_and_ipv6_cidrs(exip_method):
    # Given
    options = Namespace()
    options.sgid = "sg-123456"

    ec2 = boto3.resource('ec2')
    sg = ec2.create_security_group(
        Description='Security Group for SSH Whitelisting',
        GroupName='SSH Whitelist'
    )
    print("Created security group: {0}".format(sg.GroupId))
Run Code Online (Sandbox Code Playgroud)

而错误:

Testing started at 16:46 ...
/path/.virtualenvs/awswl-Ir8BWU8l/bin/python "/path/Library/Application Support/JetBrains/Toolbox/apps/PyCharm-P/ch-0/173.4301.16/PyCharm.app/Contents/helpers/pycharm/_jb_pytest_runner.py" --target test_commands.py::test_list_command_lists_ipv4_and_ipv6_cidrs
Launching py.test with arguments test_commands.py::test_list_command_lists_ipv4_and_ipv6_cidrs in /path/awswl/tests

============================= test session starts ==============================
platform darwin -- Python …
Run Code Online (Sandbox Code Playgroud)

python mocking boto amazon-web-services moto

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

GWTMockito 未满足的链接错误

我已经完成了 MVP 风格的大部分 GWT 测试,没有测试小部件。我希望能够构建更复杂的小部件并在不使用GwtTestCase(慢)的情况下很好地测试它们。

出于好奇,我尝试了一个极其简单的测试。给定一个非常简单的小部件,有点像这样(这不是我的确切类,只是一个简化的示例):

public class MyWidget extends Composite {
    private TextBox boxOne, boxTwo;

    public MyWidget() {
        boxOne = new TextBox();
        boxTwo = new TextBox();
        VerticalPanel panel = new VerticalPanel();
        panel.add( boxOne );
        panel.add( boxTwo );
        initWidget( panel );
    }

    public String[] getText() {
      return new String[] { boxOne.getText(), boxTwo.getText() }
    }
}
Run Code Online (Sandbox Code Playgroud)

我正在使用 GWTMockito 测试,有点像这样:

public class MyWidget extends Composite {
    private TextBox boxOne, boxTwo;

    public MyWidget() {
        boxOne = new TextBox();
        boxTwo = new …
Run Code Online (Sandbox Code Playgroud)

gwt mocking gwtmockito

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

如何使用AWS Java SDK设置AWS容器凭证

我要使用ContainerCredentialsProvider(CredentialsEndpointProvider) 代替ContainerCredentialsProvider(),因为后者已弃用。

目前,我正在使用以下弃用的构造函数ContainerCredentialsProvider()

AWSSimpleSystemsManagement ssm = 
    AWSSimpleSystemsManagementClientBuilder
        .standard()
        .withRegion(region)
        .withCredentials(new ContainerCredentialsProvider())
        .build();
Run Code Online (Sandbox Code Playgroud)

CredentialsEndpointProvider是一个抽象类。我需要ECSCredentialsEndPointProvider在docker中使用类似的内容,但我不确定该怎么做。任何帮助表示赞赏。

java amazon-web-services amazon-ecs aws-java-sdk

5
推荐指数
2
解决办法
569
查看次数

如何制作多行、下划线的UITextView/UITextField?

我想要一个具有横格纸外观的多行文本输入字段,其中每个输入行下方都有一条下划线,文本将跨越视图的宽度。

例如: 示例图像

这就是我想做的设计。行数可能会改变。

我考虑过:

  • 使用 UITextView 并放置线条背景。
  • 使用文本字段并为每个文本字段添加下划线。

这些对我来说听起来都不合理,所以我正在寻找其他可以让我指明正确方向的想法。

iphone ios swift

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

运行 SpringBootTest 时访问 H2 控制台

如果我正在运行测试,@SpringBootTest有没有办法访问 H2 控制台?我有一个访问 H2 数据库的测试(成功),但是如果我想自己检查数据库,我该怎么做?

我开始与运行测试webEnvironment=DEFINED_PORTHTTP://本地主机:8080 /响应HTTP,但没有什么的http://本地主机:8080 / H2控制台/仍以404响应。

我尝试通过向以下项添加值来显式打开控制台application.properties

spring.h2.console.enabled=true
spring.h2.console.path=/h2
Run Code Online (Sandbox Code Playgroud)

那似乎没有效果。仍然是 404/h2-console/h2

H2 控制台似乎是通过自动配置进入的,所以我使用 开启了自动配置报告-Ddebug,我可以看到尽管在 application.properties 中启用了启用标志,但它被视为关闭:

H2ConsoleAutoConfiguration: 
      Did not match:
          - @ConditionalOnProperty (spring.h2.console.enabled=true) did not find property 'enabled' (OnPropertyCondition)
      Matched:
         - @ConditionalOnClass found required class 'org.h2.server.web.WebServlet'; @ConditionalOnMissingClass did not find unwanted class (OnClassCondition)
         - found WebApplicationContext (OnWebApplicationCondition)
Run Code Online (Sandbox Code Playgroud)

似乎某种机制application.properties在运行测试时覆盖了该值或忽略了该值。

Spring Boot Test 不启动控制台吗?有什么方法可以说服它这样做吗?

spring-boot spring-boot-test

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

HttpClient 4.1.x的文档在哪里?

文档在哪里HttpClient 4.1.x

我只想要http://hc.apache.org/httpcomponents-client-4.4.x/index.html(4.4.x的文档)之类的东西


我悲伤的故事

我将要使用HttpClient 4.1.x,并且无法升级4.3.x4.4.x因为父模块(调用我的模块)使用4.1.x.这是大公司的典型问题.

首先,我想找到文档HttpClient 4.1.x,所以我打开了以下主页HttppClient:

http://hc.apache.org/

http://hc.apache.org/

但在导航中我只能找到4.3和的文档4.4.我看着这样的事情Older Versions还是Version List,但我无法找到任何东西.

然后我尝试搜索(谷歌)并找到了4.2.x主页.我希望这可能与4.1.x文档有关,但没有运气.

http://hc.apache.org/httpcomponents-client-4.2.x/index.html

http://hc.apache.org/httpcomponents-client-4.2.x/index.html

我擅长学习模式,所以我猜4.1.x主页是:

http://hc.apache.org/httpcomponents-client-4.1.x/index.html

但是,再一次,失望:

http://hc.apache.org/httpcomponents-client-4.1.x/index.html

java apache document httpclient apache-httpclient-4.x

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

使用 Oracle JET 上传文件

我正在使用Oracle JET,并且我想向我的 web 应用程序添加文件上传功能。我如何使用 Oracle JET 做到这一点?

html javascript oracle-jet

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

重命名 Terraform 目录

我想重组我的 terraform 目录——我将去多个区域并将一个大的 .tfstate 文件分解成更小的文件。作为起点,我想获取现有terraform文件夹并将其重命名为,terraform/us-east-1以便我可以添加,terraform/ca-central-1/vpc但一旦我这样做,Terraform 就会中断:

$ terraform plan
Error: Error loading modules: module mymodule: open .terraform/modules/f6d6d743c2d8bd836f32baa02d0922f7: no such file or directory

$ terraform init
Initializing modules...
- module.mymodule
Error downloading modules: Error loading modules: module mymodule: open .terraform/modules/f6d6d743c2d8bd836f32baa02d0922f7: no such file or directory
Run Code Online (Sandbox Code Playgroud)

我没有找到太多关于在搜索中重命名 terraform 文件夹的特殊方法,但我没有任何运气这样做。奇怪的是,当我测试了一些组合时,有时它似乎适用于我不想使用的组合,但我还没有弄清楚它什么时候起作用,什么时候不起作用,只是它从不适用于我正在尝试使用的名称。

建议?

terraform

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

扩展 GitInfoContributor 以添加属性?

在我发现 Spring Boot 的 Info Actuator 几乎拥有我想要发布的所有内容之前,我创建了一些元端点以确保我可以访问构建和 Git 信息,这些信息在尝试验证以下内容时会有所帮助:

  • “是否部署了正确的版本?”
  • “这是谁建的?”
  • “它什么时候建成的?”
  • “这是基于哪个 git commit?”

这样做之后,我确实开始发现 Info 执行器,它为我回答了几乎所有这些问题,但是我想添加 Git 信息中的一些内容——主要是提交消息和肮脏的旗帜。

如果我打开完整的 git 元数据,我会查看输出:

management.info.git.mode=full
Run Code Online (Sandbox Code Playgroud)

但是......这增加了更多的信息,其中大部分我并不关心,所以它比我真正想要的要多。

我想做的是获取 GitInfoContributor 并扩展/替换它,但我不完全确定如何做到这一点。添加我自己的贡献者很容易,但是如果我添加我自己的贡献者并调用 builder.withDetails("git"),如下所示:

package ca.cpp.api.submitapi.config

import org.springframework.boot.actuate.info.Info
import org.springframework.boot.actuate.info.InfoContributor
import org.springframework.boot.info.GitProperties
import org.springframework.stereotype.Component

@Component
class CustomGitInfoContributor(private val properties: GitProperties): InfoContributor {
    override fun contribute(builder: Info.Builder?) {
        builder?.withDetail("git",mapOf("dirty" to properties.get("dirty"))
    }
}
Run Code Online (Sandbox Code Playgroud)

这取代了整个 git 属性集,同时,我认为核心 GitInfoContributor 仍然存在,仍然提供我丢弃的信息。

有没有一种合理的方法来只添加我想要的元素,或者使用我自己的贡献者,可以将其信息与“git”下已有的信息合并,或者通过某种方式扩展/替换现有的 GitInfoContributor?

spring-boot spring-boot-actuator

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

在Angularjs中使用angular2

是否可以将Angular2与AngularJS混合使用?例如,在AngularJS应用程序中,有一个按钮,单击该按钮时会显示Angular2表单.什么方法合适?我应该在不同的服务器上安装应用程序,还是将Angular2应用程序重写为AngularJS?

angularjs angular2-forms angular

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