问题列表 - 第176344页

Pythonic写循环的方法

我有两个列表:a = [1, 2, 3]b = [4, 5, 6].

我在python中使用了两个循环来减去每个元素的b每个元素a.

import numpy as np
a = [1, 2, 3]
b = [4, 5, 6]
p = -1
result = np.zeros(len(a)*len(a))
for i in range(0,len(a)):
    for j in range(0,len(a)):
        p = p + 1
        result[p] = a[i] - b[j]
Run Code Online (Sandbox Code Playgroud)

我的结果是对的:result = [-3., -4., -5., -2., -3., -4., -1., -2., -3.].

但是,我想知道是否有更优雅('pythonic')的方式来做到这一点.

python loops list

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

必须为元素类型映射器声明 myBatis xml 映射导致命名空间

请问这个设置有什么明显的错误吗?在应用程序启动时,我得到属性“命名空间”必须为元素类型“映射器”声明,当它明确声明时。

spring xml资源dao.xml:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:jms="http://www.springframework.org/schema/jms"
xsi:schemaLocation="http://www.springframework.org/schema/beans
                    http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
                    http://www.springframework.org/schema/util
                    http://www.springframework.org/schema/util/spring-util-3.2.xsd
                    http://www.springframework.org/schema/jms http://www.springframework.org/schema/jms/spring-jms-2.5.xsd">

<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
    <property name="jndiName" value="java:comp/env/JNDINAME"/>
    <property name="lookupOnStartup" value="true"/>
    <property name="cache" value="true"/>
    <property name="proxyInterface" value="javax.sql.DataSource"/>      
</bean> 

<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
    <property name="dataSource" ref="dataSource" />
</bean>

<bean id="mapperScanner" class="org.mybatis.spring.mapper.MapperScannerConfigurer"> 
    <property name="basePackage" value="com.mycompany.dao"/> 
    <property name="sqlSessionFactory" ref="sqlSessionFactory"/> 
</bean>
</beans>
Run Code Online (Sandbox Code Playgroud)

界面:

public interface MyDAO {    
    public void save(@Param("id") String id);
}
Run Code Online (Sandbox Code Playgroud)

映射器xml:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
    PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
    "http://mybatis.org/dtd/mybatis-3-config.dtd">

<configuration>

<mapper namespace="com.mycompany.dao">

<typeAlias alias="xxxVO" …
Run Code Online (Sandbox Code Playgroud)

xml spring mybatis

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

在 Visual Studio Graphs 中标记轴

我试过使用指令:

Graph1.Series("Series1").Points(1).AxisLabel = "X Axis Label"
Run Code Online (Sandbox Code Playgroud)

在图形上标记 X 轴。类似的说明应适用于 Y 轴。

不幸的是,该指令产生以下错误:

ArgumentOutOfRangeException was unhandled
Index was out of range. Must be non-negative and less than the size of the collection.
Run Code Online (Sandbox Code Playgroud)

我的指令有什么问题?我该如何处理错误?

vb.net .net-4.0 visual-studio-2010

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

如何使用ng-polymer-elements,angularjs和requirejs?

我正在尝试使用具有角度和要求的ng-polymer-elements.我确实遵循了这个说明https://github.com/GabiAxel/ng-polymer-elements,但我没有成功.当我从"main.js"中删除我的需求中的"ng-polymer-elements"实例时,一切正常.有人可以帮帮我吗?谢谢.

一个小问题部分:

未捕获错误:[$ injector:modulerr]由于以下原因无法实例化模块Coderup:错误:[$ injector:nomod]模块'Coderup'不可用!您要么错误拼写了模块名称,要么忘记加载它.如果注册模块,请确保将依赖项指定为第二个参数.

main.js

    require.config({
        paths: {
             angular: '../bower_components/angular/angular',
            'angular-animate': '../bower_components/angular-animate/angular-animate',
            'angular-cookies': '../bower_components/angular-cookies/angular-cookies',
            'angular-mocks': '../bower_components/angular-mocks/angular-mocks',
            'angular-resource': '../bower_components/angular-resource/angular-resource',
            'angular-sanitize': '../bower_components/angular-sanitize/angular-sanitize',
            'angular-scenario': '../bower_components/angular-scenario/angular-scenario',
            'angular-touch': '../bower_components/angular-touch/angular-touch',
             bootstrap: '../bower_components/bootstrap/dist/js/bootstrap',
            'ng-polymer-elements' : '../bower_components/ng-polymer-elements/ng-polymer-elements.min',
             platform : '../bower_components/platform/platform',
            'uiRouter' : '../bower_components/angular-ui-router/release/angular-ui-router',
            jquery : '../bower_components/jquery/dist/jquery.min'
        },
        shim: {
            angular: {
                deps: ['platform'],
                exports: 'angular'
            },
            platform : {
                exports : 'platform'
            },
            jquery : {
                exports: 'jquery'
            },
            'ng-polymer-elements' : [
                'angular'
            ],
            'uiRouter': [
                'angular'
            ],
            'angular-cookies': [
                'angular'
            ],
            'angular-sanitize': [
                'angular' …
Run Code Online (Sandbox Code Playgroud)

requirejs angularjs polymer material-design angular-material

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

是否有机会在iTunes Connect上为消费品注册In App Purchase的回调URL?

我们正在从StoreKit读取收据并将NSData发送到我们的服务器.我们使用https://github.com/chrismaddern/iOS-Receipt-Validator-PHP验证数据,之后我们在云系统中进行预订交易并将交易标记为已完成.但是,如果客户(用户)的数据连接在购买交易期间中断,该怎么办?然后我们永远不会收到带有收据数据的请求,我们无法在服务器端完成该过程.因此,如果Apple在In App Purchase中为每个新交易提交回调,那将是完美的.因此,我们可以检查客户在应用程序中购买产品的时间.想法?

storekit in-app-purchase ios

6
推荐指数
0
解决办法
723
查看次数

可以基于type_info创建对象吗?

几乎所有标题:可以基于创建对象type_info吗?这样做的目的是推迟创建对象.例如,这是原始的"未延期"代码:

Foo* a = new Foo();
Bar* b = new Bar();
Run Code Online (Sandbox Code Playgroud)

这是推迟的:

// Store type indices into a vector
std::vector<std::type_index> types;
types.push_back(std::type_index(typeid(Foo)));
types.push_back(std::type_index(typeid(Bar)));

// Iterate through vector, create objects? Is it possible?
Run Code Online (Sandbox Code Playgroud)

如果这是不可能的,还有其他方法来"推迟"对象的构造吗?

c++

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

如何根据要求编写Flask装饰器?

我不确定为什么以下装饰器[validate_request]不起作用.编写此类验证装饰器的正确方法是什么?

def validate_request(req_type):
    if req_type is 'json' and not request.json:
        abort(400)
    def decorator(func):
        @functools.wraps(func)
        def wrapped_func(*args, **kwargs):
            return func(*args, **kwargs)
        return wrapped_func
    return decorator

@app.route('/todo/api/v1.0/tasks/<int:task_id>', methods=['PUT'])
@validate_request('json')
@json
def update_task(task_id):
#    task = filter(lambda t: t['id'] == task_id, tasks)
    task = [task for task in tasks if task['id'] == task_id]
    if len(task) == 0:
        abort(404)

    #update task
    for field in ['title', 'description', 'done']:
        task[0][field] = request.json.get(field, task[0][field])
Run Code Online (Sandbox Code Playgroud)

错误: -

Traceback (most recent call last):
  File "C:\AGR\Programming\LearningPython\FlaskLearning\flask_rest\app.py", line 156, in <module> …
Run Code Online (Sandbox Code Playgroud)

python flask python-decorators

9
推荐指数
2
解决办法
6828
查看次数

如何使用Alamofire记录每个请求/响应?

有没有办法使用Alamofire记录每个请求/响应(类似于AFNetworkActivityLogger)?

我知道Printable,DebugPrintable和Output(cURL),但它们并不是我想要的.

debugging ios afnetworking-2 alamofire

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

如何在QT中将时间缩短到下一个小时?

这是代码:

startDate->setDateTime( QDateTime::currentDateTime() );
finishDate->setDateTime( QDateTime::currentDateTime() );
finishDate->setDateTime(startDate->dateTime().addSecs( 3600 ));
Run Code Online (Sandbox Code Playgroud)

例如现在的时间是13:34

我需要将开始时间四舍五入到14:00.也可以将结束时间四舍五入到15:00

任何人对如何做到这一点都有任何想法?还请举个例子吗?感谢:D

qt

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

Angularjs在窗口大小调整时更改范围变量

我正在尝试更改范围变量:$scope.tab每次窗口调整大小时$scope.tab == 'more'.

码:

$scope.closeMoreTab = function() {
    if($scope.tab == 'more')
        $scope.tab = 'extras';
};

angular.element($window).bind('resize', function() {
    $scope.closeMoreTab();
});
Run Code Online (Sandbox Code Playgroud)

好吧,它确实在调用$scope.closeMoreTab(),而且它确实在改变$scope.tab变量,但实际上,它并没有改变视图上的任何内容.

我试过了:

console.log($scope);
Run Code Online (Sandbox Code Playgroud)

要检查变量tab,它确实变为'extras',但是当我这样做时:

<div>{{ tab }}</div>
Run Code Online (Sandbox Code Playgroud)

它告诉我,当前的tab变量仍然是"更多"

请帮忙.我坚持了1个小时,不知道为什么会这样或者做什么.

非常感谢

javascript scope angularjs

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