当我运行 pytest 时,我收到了来自 3rd 方库的一些弃用警告。我想知道我自己代码中的任何弃用警告,而不是与另一个 3rd 方库捆绑在一起的库的供应商副本。
这个答案有助于让我中途到达那里。如果我像这样运行 pytest:
$ pytest ./tests/我得到:
$ pytest ./tests/
============================= test session starts ==============================
platform linux -- Python 3.7.4, pytest-5.2.1, py-1.8.0, pluggy-0.13.0
rootdir: /home/whlt/repos/tj-image-resizer/tests, inifile: pytest.ini
collected 5 items
tests/test_file1.py . [ 20%]
tests/test_file2.py .... [100%]
=============================== warnings summary ===============================
/home/whlt/.local/lib/python3.7/site-packages/botocore/vendored/requests/packages/urllib3/_collections.py:1
/home/whlt/.local/lib/python3.7/site-packages/botocore/vendored/requests/packages/urllib3/_collections.py:1
/home/whlt/.local/lib/python3.7/site-packages/botocore/vendored/requests/packages/urllib3/_collections.py:1: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working
from collections import Mapping, MutableMapping
-- Docs: https://docs.pytest.org/en/latest/warnings.html …Run Code Online (Sandbox Code Playgroud) 在我的结构应用程序中,我正在侦听某些按键,例如删除键,并删除任何选定的元素.我按键按键的方法是:
document.onkeydown = function(e) {
if (46 === e.keyCode) {
// 46 is Delete key
// do stuff to delete selected elements
}
Run Code Online (Sandbox Code Playgroud)
我遇到了一个问题:我有其他元素,如页面上的文本框,当在文本框中键入时,我不希望删除键删除任何元素.
在这个问题中,有一个描述将事件监听器附加到HTML5画布的方法:
canvas.tabIndex = 1000;
Run Code Online (Sandbox Code Playgroud)
允许您使用canvas.addEventListener键盘事件.
我可以用布料的画布使用类似的东西吗?
我这样试试的时候,
var CANVAS = new fabric.Canvas('elemID', {selection: false})
CANVAS.tabIndex = 1000;
CANVAS.addEventListener("keydown", myfunc, false);
Run Code Online (Sandbox Code Playgroud)
我从Chrome获得"Uncaught TypeError:undefined is not function".
我试图在Ubuntu上本地运行AWS Lambda项目。当我使用AWS SAM Local运行项目时,它显示此错误:Error: Running AWS SAM projects locally requires Docker. Have you got it installed?
当我尝试运行以下代码时,我得到一个seg错误.我已经尝试通过gdb运行它,我知道错误是作为调用的一部分发生的printf,但我迷失了为什么它无法正常工作.
#include <stdlib.h>
#include <stdio.h>
int main() {
char c[5] = "Test";
char *type = NULL;
type = &c[0];
printf("%s\n", *type);
}
Run Code Online (Sandbox Code Playgroud)
如果我更换printf("%s\n", *type);
,printf("%s\n", c);我按照预期打印"测试".为什么它不能用于指向char数组的指针?
我正在使用fabric.js在画布上绘制一些文本.我有一个创建文本标签的功能.我想让标签在选中时运行一个功能.这个的语法是label.on('selected', functionToCall());当我使函数成为一个匿名的内部函数时这很好用,但当我把它作为一个单独的函数分解时,我得到一个未捕获的TypeError : Cannot read property 'hasOwnProperty' of undefined. 我究竟做错了什么?
以下代码对我不起作用.这是jsfiddle 上的破解代码,以及使用匿名函数设置的版本.
"use strict";
var canvas = new fabric.Canvas('c', {selection: false}),
position = 50;
function onLabelSelection(theLabel) {
if (theLabel.hasOwnProperty('edge')) {
selectedEdge = theLabel.edge;
} else {
selectedEdge = null;
}
}
function createLabel() {
var label;
label = new fabric.Text('Hello World', {
left: position,
top: position
});
position += 50;
label.edge = null;
label.on('selected', onLabelSelection(this));
return label;
}
canvas.on('mouse:up', function() {
var newLabel …Run Code Online (Sandbox Code Playgroud) 当我正在调用的函数有很多参数,而且我想要有条件地包含一个函数时,我是否必须对该函数进行两次单独的调用,或者是否有一些东西不通过(几乎就像None)以便我我没有传递任何特定参数的参数?
例如,我想sixth有时传递参数的参数,但有时我想不传递该参数的任何内容.这段代码有效,但感觉我复制的次数超出了我的要求.
我正在调用的函数位于第三方库中,因此我无法更改它处理接收参数的方式.如果我通过None了sixth,将抛出一个异常.我需要通过我'IMPORTANT_VALUE'或不通过任何东西.
我目前在做什么:
def do_a_thing(stuff, special=False):
if special:
response = some.library.func(
first=os.environ['first'],
second=stuff['second'],
third=stuff['third']
fourth='Some Value',
fifth=False,
sixth='IMPORTANT_VALUE',
seventh='example',
eighth=True
)
else:
response = some.library.func(
first=os.environ['first'],
second=stuff['second'],
third=stuff['third']
fourth='Some Value',
fifth=False,
seventh='example',
eighth=True
)
return response
Run Code Online (Sandbox Code Playgroud)
我想做什么:
def do_a_thing(stuff, special=False):
special_value = 'IMPORTANT_VALUE' if special else EMPTY_VALUE
response = some.library.func(
first=os.environ['first'],
second=stuff['second'],
third=stuff['third']
fourth='Some Value',
fifth=False,
sixth=special_value,
seventh='example',
eighth=True
)
return response
Run Code Online (Sandbox Code Playgroud) What is the simplest way to pretty-print a string of JSON as a string with indentation when the initial JSON string is formatted without extra spaces or line breaks?
Currently I'm running json.loads() and then running json.dumps() with indent=2 on the result. This works, but it feels like I'm throwing a lot of compute down the drain.
Is there a more simple or efficient (built-in) way to pretty-print a JSON string? (while keeping it as valid JSON)
Example
import requests …Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一个运行类函数的线程.我认为我做错事的地方靠近我所在的主要地方RowChecker r0(puz, 0, s); thread rt0 {r0.check()};.我的编译器(g ++)告诉我,no matching function for call to ‘std::thread::thread(<brace-enclosed initializer list>)’
所以我理解我没有正确地进行调用.格式化此调用以创建新线程的正确方法是什么?
#include <iostream>
#include <thread>
using namespace std;
class Sum
{
private:
int sum;
public:
Sum();
int getSum();
void addSum();
};
class RowChecker
{
private:
int puz[9][9];
int myRow;
Sum* sum;
public:
RowChecker(int puzzel[9][9], int row, Sum* shared);
void check();
};
Sum::Sum() {
sum = 0;
}
int Sum::getSum() {
return sum;
}
void Sum::addSum() {
++sum;
}
RowChecker::RowChecker(int puzzel[9][9], int …Run Code Online (Sandbox Code Playgroud) 给定一组名称 - 值对的dicts,将它们转换为字典的最有效或最Pythonic方法是什么,名称为键,值为值?
这就是我的想法.它很短,似乎工作正常,但有没有一些内置函数来做这种事情?
verbose_attributes = [
{
'Name': 'id',
'Value': 'd3f23fa5'
},
{
'Name': 'first_name',
'Value': 'Guido'
},
{
'Name': 'last_name',
'Value': 'van Rossum'
}]
attributes = {}
for pair in verbose_attributes:
attributes[pair['Name']] = pair['Value']
print(repr(attributes))
# {'id': 'd3f23fa5', 'first_name': 'Guido', 'last_name': 'van Rossum'}
Run Code Online (Sandbox Code Playgroud)
简而言之,是否有更好的转换verbose_attributes方式attributes?
python ×4
python-3.x ×2
aws-lambda ×1
aws-sam-cli ×1
c ×1
c++ ×1
c++11 ×1
fabricjs ×1
javascript ×1
json ×1
pytest ×1
stdthread ×1
ubuntu ×1