小编Mic*_*x2a的帖子

将Gradle升级到版本4后生成错误

当我将Android项目中的Gradle升级到版本4时,我们遇到此错误并无法修复它.

错误详情:

More than one variant of project :volley matches the consumer attributes:
  - Configuration ':volley:debugApiElements' variant android-aidl:
      - Found artifactType 'android-aidl' but wasn't required.
      - Required com.android.build.api.attributes.BuildTypeAttr 'debug' and found compatible value 'debug'.
      - Found com.android.build.api.attributes.VariantAttr 'debug' but wasn't required.
      - Required com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' and found compatible value 'Aar'.
      - Required org.gradle.usage 'java-api' and found compatible value 'java-api'.
  - Configuration ':volley:debugApiElements' variant android-classes:
      - Found artifactType 'android-classes' but wasn't required.
      - Required com.android.build.api.attributes.BuildTypeAttr 'debug' and found compatible value 'debug'. …
Run Code Online (Sandbox Code Playgroud)

android gradle

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

Rspec redirect_to显示操作

我正在学习rails并且遇到了Rspec的问题.我对控制器进行了以下测试:

describe PostsController, "creating a new post" do
  it "should redirect and show the post" do
    Post.stub!(:save).and_return(true)
    post "create"
    response.should redirect_to :action => "show"
  end
end
Run Code Online (Sandbox Code Playgroud)

当我运行此测试时,我遇到以下故障:

PostsController creating a new post should redirect and show the post
Failure/Error: response.should redirect_to :action => "show"
ActionController::RoutingError:
  No route matches {:action=>"show", :controller=>"posts"}
  # ./spec/controllers/posts_controller_spec.rb:8:in `block (2 levels) in <top       (required)>'
Run Code Online (Sandbox Code Playgroud)

然而,当我检查我的路线时,我看到我的帖子控制器的显示动作:

post GET    /posts/:id(.:format)      {:action=>"show", :controller=>"posts"}
Run Code Online (Sandbox Code Playgroud)

我可能错过了一些非常简单但很难找到它的东西.

谢谢.

ruby-on-rails rspec2

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

在Tkinter Canvas Widget内移动一个球(简单的Arkanoid游戏)

我试图在Python和Tkinter的帮助下编写一个简单的Arkanoid.目标是让球从顶部,右侧和左侧反射.如果球员错过球而接触到底部,则比赛将停止.

这是代码:

from Tkinter import *
import time

root = Tk()
canv = Canvas(root, highlightthickness=0)
canv.pack(fill='both', expand=True)
top = canv.create_line(0, 0, 640, 0, fill='green', tags=('top'))
left = canv.create_line(0, 0, 0, 480, fill='green', tags=('left'))
right = canv.create_line(639, 0, 639, 480, fill='green', tags=('right'))
bottom = canv.create_line(0, 478, 640, 478, fill='red', tags=('bottom'))

rect = canv.create_rectangle(270, 468, 365, 478, outline='black', fill='gray40', tags=('rect'))
ball = canv.create_oval(0, 20, 20, 40, outline='black', fill='gray40', tags=('ball'))

delta_x = delta_y = 3
new_x, new_y = delta_x, -delta_y
while True:
    time.sleep(0.025) …
Run Code Online (Sandbox Code Playgroud)

python canvas tkinter

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

Rails + Postgres:如何选择更新或插入的记录数?

所以我有一个更新声明:

UPDATE billing_infos set card_number = ''
FROM orders
WHERE billing_infos.order_id = orders.id ...);`
Run Code Online (Sandbox Code Playgroud)

我如何找到此语句更新的记录数?

我正在我的控制台中执行此操作,ActiveRecord::Base.connection.execute()因此它只是返回一个<PG::Result:0x007f9c99ef0370>对象。

任何人都知道我如何使用 SQL 或 Rails 方法来做到这一点?

postgresql ruby-on-rails

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

无法理解为什么字母u前缀我的raw_input()输出

我目前正在学习Python,并编写了一个程序来试验这门语言.但是,每当我使用它时,输出总是在其中有一个字母"u".我正在使用Pyscripter作为我的IDE.

这是我的代码:

print "whats your name"
age = raw_input()
print "Alright, so %r, I just realized what percent-r does actually or is meant for" % (age)
print "What next ur age",
age1 = raw_input()
print "you entered %r " % (age1)
Run Code Online (Sandbox Code Playgroud)

当我运行它时,我看到这样的事情:

>>> Python 2.7.5 (default, May 15 2013, 22:43:36) [MSC v.1500 32 bit (Intel)] on win32.

>>> whats your name (i typed kk)

>>> Alright, so u'kk', i just realized what percent-r does actually or is meant for

>>> …
Run Code Online (Sandbox Code Playgroud)

python unicode raw-input

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

这些C指针操作会导致问题吗?

让我说我得到了:

char *p = NULL;
Run Code Online (Sandbox Code Playgroud)

我确定这个会出现问题,因为我要取消引用一个NULL指针:

*p = 16;
Run Code Online (Sandbox Code Playgroud)

另一方面,我认为这个可以,因为我得到*p的地址NULL本身不是:

char **pp = &p;
Run Code Online (Sandbox Code Playgroud)

在这两种情况下我都是对的吗?

c theory pointers lvalue dereference

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

matplotlib中的轴重叠线

我正在尝试在matplotlib图上绘制一系列任意行.这是我正在使用的代码:

import matplotlib.pyplot as pyplot

def center_origin(axis):
    '''Center the axis in the middle of the picture'''
    axis.spines['right'].set_color('none')
    axis.spines['top'].set_color('none')
    axis.xaxis.set_ticks_position('bottom')
    axis.spines['bottom'].set_position(('data',0))
    axis.yaxis.set_ticks_position('left')
    axis.spines['left'].set_position(('data',0))

def render(lines):
    figure = pyplot.figure(figsize=(4,4))
    axis = figure.add_subplot(1, 1, 1)

    center_origin(axis)        

    for (x1, y1), (x2, y2) in lines:
        axis.add_line(pyplot.Line2D((x1, x2), (y1, y2), color='red'))

    axis.set_xlim(-1.2, 1.2)
    axis.set_ylim(-1.2, 1.2)
    return figure

if __name__ == '__main__':
    render([((1, 0), (0, 1)),
            ((1, 0), (-1, 0)),
            ((1, 0), (0, -1))]).show()
    raw_input('block > ')
Run Code Online (Sandbox Code Playgroud)

它生成一个如下所示的图形:

坏图

目前,x轴覆盖应该从(1,0)到(-1,0)的红线.我尝试center_origin在绘制线之前和之后将函数放置到两者,但没有任何改变.

如何让matplotlib在轴上绘制线条?

python graphing matplotlib

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

在Python中使用Sage Math库

我正在尝试使用Sage对图形进行可视化.我需要完全像编写Python代码一样进行可视化.

我已经下载并安装了Sage for Ubuntu和Sage Notebook正常运行.但我想从Tkinter获取用户输入,然后在Graph上显示这些输入(由Sage生成).但是,我无法在Python Shell中导入sage.我怎么能这样做?

python sage python-2.7

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

在运行时创建动态命名的函数

我正在创建一个名为的简单包pyma,可在pypi上找到.

我提供了一种计算N日指数移动平均值的方法,该函数称为NDayEMA(n, data).(事实上​​,它是一个名为的类NDayEMA,带有一个被调用的函数,compute()但它在这里是无关紧要的.)

我试图在运行时创建一个动态命名的函数作为用户的快捷方式.

例如:

NDayEMA(30, data) 
Run Code Online (Sandbox Code Playgroud)

EMA30(data)
Run Code Online (Sandbox Code Playgroud)

会是一样的

EMA23(data)
EMA1023(data)
EMA12(data)
Run Code Online (Sandbox Code Playgroud)

也可以.

我知道我需要一些注册和处理,这在你的答案中是不需要的; 我自己会得到它!我正在搜索如何接收用户提供的函数的名称,并创建具有该名称的函数,而不会引发错误消息.

这是来自Laravel PHP框架的PHP等价物.

$user = DB::table('users')->where_email_and_password('example@gmail.com', 'secret');
Run Code Online (Sandbox Code Playgroud)

python python-2.7

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

试图将文件加载到Python中,但它声明它不存在,即使它确实存在

我正在尝试将csv文件加载到Pandas中.我得到一个奇怪的错误,我以前从未遇到过该文件即使存在也不存在.该错误还在消息"ree.csv"中将文件调用为其他名称

import pandas as pd
tree = pd.read_csv('C:\Users\Desktop\tree.csv')
Run Code Online (Sandbox Code Playgroud)
IOError                                   
Traceback (most recent call last)
<ipython-input-63-aed3b96442f2> in <module>()
----> 1 tree = pd.read_csv('C:\Users\Desktop\tree.csv')

C:\Users\AppData\Local\Continuum\Anaconda\lib\site-packages\pandas\io\parsers.pyc in parser_f(filepath_or_buffer, sep, dialect, compression, doublequote, escapechar, quotechar, quoting, skipinitialspace, lineterminator, header, index_col, names, prefix, skiprows, skipfooter, skip_footer, na_values, na_fvalues, true_values, false_values, delimiter, converters, dtype, usecols, engine, delim_whitespace, as_recarray, na_filter, compact_ints, use_unsigned, low_memory, buffer_lines, warn_bad_lines, error_bad_lines, keep_default_na, thousands, comment, decimal, parse_dates, keep_date_col, dayfirst, date_parser, memory_map, nrows, iterator, chunksize, verbose, encoding, squeeze, mangle_dupe_cols, tupleize_cols)
    398             )
    399 
--> …
Run Code Online (Sandbox Code Playgroud)

python

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