小编tev*_*dar的帖子

为什么输出结果不同?

async function fn1() {
  return 1
}
async function fn2() {
  return Promise.resolve(1)
}

function fn3() {
  return Promise.resolve(1)
}

function fn4() {
  return Promise.resolve(Promise.resolve(1))
}
console.log(fn1()); //Promise {<fulfilled>: 1}
console.log(fn2()); // Promise {<pending>}
console.log(fn3()); // Promise {<fulfilled>: 1}
console.log(fn4()); // Promise {<fulfilled>: 1}
Run Code Online (Sandbox Code Playgroud)

当我运行 fn2() 时,它输出Promise { pending }.

为什么是 fn2()Promise { pending }而不是Promise {fulfilled: 1}

javascript

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

如何从可编辑表格更新绘图/虚线图?

我有一个带有可删除行和列的破折号 DataTable 对象。我想根据可见行更新数字。我不确定如何创建回调以及要传递哪些参数。当在浏览器中删除行时,存储在表对象中的数据实际上可能不会改变。

from dash_table import DataTable

def lineplot(id, df, cols, title=None, xlabel=None, ylabel=None, x=None, 
             xaxis_type=None, yaxis_type=None, plotly_config=plotly_config,
            ):

    if x is None:
        x_values = df.index
        xlabel = df.index.name
    else:
        x_values = df[x]

    data = [{
        'x': x_values,
        'y': df[col],
        'name': col }  for col in cols]

    layout = go.Layout(
        title=go.layout.Title(
            text=title,
            xref='paper',
            xanchor='center'
        ),
        xaxis = go.layout.XAxis(
            title=go.layout.xaxis.Title(
                text=xlabel,
                font=plotly_config['font'],

            ),
            type=xaxis_type
        ),
        yaxis=go.layout.YAxis(
            title=go.layout.yaxis.Title(
                text=ylabel,
                font=plotly_config['font'],
            ),
        type=yaxis_type
        ),
        showlegend=True
    )


    return dcc.Graph(
        id=id,
        figure={'data': data,
                'layout': layout}, …
Run Code Online (Sandbox Code Playgroud)

plotly plotly-dash

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

破折号dataTable条件单元格格式不起作用

我想根据一个值更改Dash dataTable单元格的颜色。我尝试了一个最小的例子:

            html.Div(
            children=[
                dash_table.DataTable(
                    id='table_1',
                    data=df.to_dict('records'),
                    columns=[{"name": i, "id": i} for i in df.columns],
                    #conditional cell formating
                    style_data_conditional=[
                        {
                            'if': {
                                'column_id': 'col1',
                                'filter': 'col1 > num(15)'
                            },
                            'backgroundColor': '#3D9970',
                            'color': 'white',
                        },
                    ],
                    n_fixed_rows=2,
                    filtering=True,
                    sorting=True,
                    sorting_type="multi"
                )],
        )
Run Code Online (Sandbox Code Playgroud)

添加style_conditional之后,该表根本不会显示,并且不会引发任何错误消息。该表嵌入在html组件中,进入论坛和github后,我不确定是否在这里错过了任何内容,以及是否需要为此编写回调函数。提到的教程中提供的示例并不建议需要回调。

更新:

尝试使用相同的代码和不同的数据运行最低版本,并获得相同的结果,即单元格颜色不变。我的库是最新的,但是环境中的某些内容仍可能会引起问题。

完整代码:

import dash
import dash_table
import pandas as pd

df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/solar.csv')

# Having trouble with conditional when column name has spaces
df = df.rename({'Number of Solar Plants': 'Plants'}, axis='columns')
app = …
Run Code Online (Sandbox Code Playgroud)

python plotly plotly-dash

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

django-plotly-dash div 尺寸太小并且不会改变

使用 Django-plotly-dash 模块和 dash 应用程序在一个非常小的窗口中渲染。除了典型的 css 之外,我还能做些什么来渲染这个完整的页面吗?

我尝试过更新特定 div 的样式以及更新整个页面中的样式。

...

{% extends 'base_page.html' %}
{% block content %}
<head>

</head>
<body>
{%load plotly_dash%}

    <div class={% plotly_class name="SimpleExample"%}>

        {% plotly_app name="SimpleExample" %}
      </div>
</body>
{% endblock %}
...
Run Code Online (Sandbox Code Playgroud)

期望 div 是整页,但它只呈现一个非常小的窗口

css django plotly plotly-dash

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

同时循环C中的开关案例

我最近遇到了下面显示的代码片段,我原以为它是一个语法错误,但令我惊讶的是,代码产生了有效的输出.

#include <stdio.h>

int main(void) {
    int x = 2;

    switch(x) {
    case 1: printf("1"); break;

        do {
            case 2: printf("2 "); break;
            case 3: printf("3 "); break;
        } while(++x < 4);

        case 4: printf("4"); break;
    }
    return 0;
}
Run Code Online (Sandbox Code Playgroud)
output: 2 4
Run Code Online (Sandbox Code Playgroud)

编译器:GCC 6.3

我发现了一个类似的问题,但它并不能完全证明上述条件, 在C中混合'切换'和'同时'

谁能解释一下,

  1. 究竟发生了什么?
  2. 为什么不是语法错误?
  3. 为什么会跳过"3"的情况?

c while-loop switch-statement

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

JavaScript-生成数组的所有排列

我有不同的数组,都带有数字,但是元素数量不同:

var ar1 = [2, 5];
var ar2 = [1, 2, 3];
Run Code Online (Sandbox Code Playgroud)

我需要获取每个数组的所有排列。输出元素的长度应始终与输入数组相同。

此结果应该是一个数组数组,如下所示:

对于ar1:

[2, 5]
[5, 2]
Run Code Online (Sandbox Code Playgroud)

对于ar2:

[1, 2, 3]
[1, 3, 2]
[2, 1, 3]
[2, 3, 1]
[3, 1, 2]
[3, 2, 1]
Run Code Online (Sandbox Code Playgroud)

我不想要笛卡尔积,每个数组都应该自己处理。

到目前为止,我发现的所有解决方案都仅创建与顺序无关的数组,因此ar1的结果仅是一个数组,而不是两个。

解决方案应适用于输入数组中任意数量的元素。我们可以假设输入数组中没有重复的值。

javascript arrays permutation

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

重定位 R_X86_64_PC32 针对未定义的隐藏符号`__dso_handle' 制作共享对象时不能使用

我想在 Python 中使用 C++ 函数。因此,我决定为此目的尝试使用 SWIG。首先,我运行命令:

swig -python test.i
Run Code Online (Sandbox Code Playgroud)

然后用g++-6.2编译如下:

g++-6.2 -c test.cpp test_wrap.c -fPIC -I /usr/include/python3.6m
Run Code Online (Sandbox Code Playgroud)

目前一切正常,但问题出现在必须创建链接的最后一步。我运行命令:

ld -shared test.o test_wrap.o -o _test.so
Run Code Online (Sandbox Code Playgroud)

正如Swig 教程中所建议的,但我收到以下错误:

test.o: In function `__static_initialization_and_destruction_0(int, int)':
test.cpp:(.text+0x66): undefined reference to `__dso_handle'
ld: test.o: relocation R_X86_64_PC32 against undefined hidden symbol `__dso_handle' can not be used when making a shared object
ld: final link failed: Bad value
Run Code Online (Sandbox Code Playgroud)

有谁知道如何解决这一问题?

c c++ python swig ld

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

如何按长度对字符串排序

我遇到了对数组中的字符串进行排序的问题。我能够对整数进行排序,但是我真的不知道如何将字符串从最短到最长排序。

我尝试使用Strings.length将Strings转换为整数,但是我不知道如何将其转换回其原始String。

字符串处理程序;

        System.out.println("\nNow we will sort String arrays.");
        System.out.println("\nHow many words would you like to be sorted.");
        Input = in.nextInt();
        int Inputa = Input;
        String[] Strings = new String [Input];
        for (int a = 1; a <= Input; Input --) //will run however many times the user inputed it will
    {
        counter ++; //counter counts up
        System.out.println("Number " + counter + ": "); //display 
        userinputString = in.next();
        Strings[countera] = userinputString;  //adds input to array
        countera ++;
    }
        System.out.println("\nThe words …
Run Code Online (Sandbox Code Playgroud)

java arrays sorting string

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