浅紫色的梦幻

文章 评论 浏览 28

浅紫色的梦幻 2025-02-20 18:04:24

最简单的方法是使用slice note .loc 以及您与 .drop 的调用一起删除任何特定不需要的列:

创建数据

>>> df = pd.DataFrame([[*range(10)]]*5, columns=[*'abcdefghij'])
>>> df
   a  b  c  d  e  f  g  h  i  j
0  0  1  2  3  4  5  6  7  8  9
1  0  1  2  3  4  5  6  7  8  9
2  0  1  2  3  4  5  6  7  8  9
3  0  1  2  3  4  5  6  7  8  9
4  0  1  2  3  4  5  6  7  8  9

.loc .loc < /code>并相当简单地删除

,请使用 .loc 执行切片,然后 drop 从那里您不想要的任何东西。

>>> df.loc[:, 'a':'g'].drop(columns='b')
   a  c  d  e  f  g
0  0  2  3  4  5  6
1  0  2  3  4  5  6
2  0  2  3  4  5  6
3  0  2  3  4  5  6
4  0  2  3  4  5  6

使用索引

,如果要在索引中尽可能高效地工作,则可以将 index.slice_indexer .drop 一起使用,这样您就不会创建临时子集您的数据(就像我们上面所做的那样):

>>> columns = df.columns[df.columns.slice_indexer('a', 'g')].drop('b')
>>> df[columns]
   a  c  d  e  f  g
0  0  2  3  4  5  6
1  0  2  3  4  5  6
2  0  2  3  4  5  6
3  0  2  3  4  5  6
4  0  2  3  4  5  6

The easiest way will be to use slice notation .loc as you demonstrated along with a call to .drop to remove any specific unwanted columns:

Create data

>>> df = pd.DataFrame([[*range(10)]]*5, columns=[*'abcdefghij'])
>>> df
   a  b  c  d  e  f  g  h  i  j
0  0  1  2  3  4  5  6  7  8  9
1  0  1  2  3  4  5  6  7  8  9
2  0  1  2  3  4  5  6  7  8  9
3  0  1  2  3  4  5  6  7  8  9
4  0  1  2  3  4  5  6  7  8  9

.loc and dropping

Fairly straightforward, use .loc to perform your slicing then drop anything you don't want from there.

>>> df.loc[:, 'a':'g'].drop(columns='b')
   a  c  d  e  f  g
0  0  2  3  4  5  6
1  0  2  3  4  5  6
2  0  2  3  4  5  6
3  0  2  3  4  5  6
4  0  2  3  4  5  6

Working With the Index

If you want to work as efficiently as possible with the index, you can use Index.slice_indexer along with .drop so that you don't create temporary subsets of your data (like we did above):

>>> columns = df.columns[df.columns.slice_indexer('a', 'g')].drop('b')
>>> df[columns]
   a  c  d  e  f  g
0  0  2  3  4  5  6
1  0  2  3  4  5  6
2  0  2  3  4  5  6
3  0  2  3  4  5  6
4  0  2  3  4  5  6

从数据框架中选择特定列

浅紫色的梦幻 2025-02-20 15:18:10

如果您通过 values 模块使用接口,则数组的元素也需要为 value ,因此它们也可以轻量级。没有这些信息,它将无法确定数组元素的大小。

If you use an interface via the values module, the elements of the array also need to be values so they can be flyweights as well. Without this information, it can't determine how large the elements of the array will be.

编年史值:返回数组而不是单个项目的Getter

浅紫色的梦幻 2025-02-20 03:17:25

您可以按以下方式重写一点。

sed -i 's/\(PlayButton-playCircle-kffp_v{.*\)display:inline-block/\1display:none/g' file.css

\( \)之间的文本将被捕获,可以在替换字符串中引用为 \ 1

You can rewrite it a bit as follows.

sed -i 's/\(PlayButton-playCircle-kffp_v{.*\)display:inline-block/\1display:none/g' file.css

The text between \( and \) will be captured and can be referenced as \1 in the replacement string.

SED替换为CSS中未知部分

浅紫色的梦幻 2025-02-19 12:21:57

似乎您打算计算交叉点两组

const x = [1, 3, 7, 4, 9];
const y = [2, 3, 9, 13, 4];

function intersection(setA, setB) {
  let _intersection = new Set()
  for (let elem of setB) {
    if (setA.has(elem)) {
      _intersection.add(elem)
    }
  }
  return _intersection
}

const setX = new Set(x);
const setY = new Set(y);

const commonSet = intersection(setX, setY);

console.log(...commonSet); // [3, 9, 4]

It seems like you intend to calculate the intersection of two sets, thus the corresponding function operation from the mozilla developer docs can be used, e.g.

const x = [1, 3, 7, 4, 9];
const y = [2, 3, 9, 13, 4];

function intersection(setA, setB) {
  let _intersection = new Set()
  for (let elem of setB) {
    if (setA.has(elem)) {
      _intersection.add(elem)
    }
  }
  return _intersection
}

const setX = new Set(x);
const setY = new Set(y);

const commonSet = intersection(setX, setY);

console.log(...commonSet); // [3, 9, 4]

合并数组在两者中仅具有元素(有效)

浅紫色的梦幻 2025-02-19 03:33:14

删除第二个软件包声明和解决错误。之后,再次运行。

Remove the second package declaration and the resolving errors. After that, run it again.

您好,我收到的错误消息“线程”中的“主”例外”。 java.lang.error:未解决的汇编问题:在Eclipse IDE

浅紫色的梦幻 2025-02-18 17:01:19

要在查询结果中显示第一行:

print(db_rows.fetchone())

显示查询的所有结果:

print(db_rows.fetchall())

for row in db_rows.fetchall():
    print(row)

To show the first row in the results of the query:

print(db_rows.fetchone())

To show all of the results of the query:

print(db_rows.fetchall())

or

for row in db_rows.fetchall():
    print(row)

在Python查询中仅显示一个数据

浅紫色的梦幻 2025-02-18 09:39:58

这应该有效

代码:

list = ['A', 'B', 'C', 'D', 'E']

print(f"The first three items in the list are: {', '.join(list[0:3])}")

输出:

The first three items in the list are: A, B, C

This should work

Code:

list = ['A', 'B', 'C', 'D', 'E']

print(f"The first three items in the list are: {', '.join(list[0:3])}")

Output:

The first three items in the list are: A, B, C

如何将文本和列表凝结成一行代码?

浅紫色的梦幻 2025-02-18 08:50:07

这里的大多数答案给出了一个有用的建议,何时进行单个异步操作,但是有时候,当您需要在数组或其他类似列表的结构中为每个每个条目进行异步操作时,这会出现。诱惑是这样做:

// WRONG
var results = [];
theArray.forEach(function(entry) {
    doSomethingAsync(entry, function(result) {
        results.push(result);
    });
});
console.log(results); // E.g., using them, returning them, etc.

示例:

// WRONG
var theArray = [1, 2, 3];
var results = [];
theArray.forEach(function(entry) {
    doSomethingAsync(entry, function(result) {
        results.push(result);
    });
});
console.log("Results:", results); // E.g., using them, returning them, etc.

function doSomethingAsync(value, callback) {
    console.log("Starting async operation for " + value);
    setTimeout(function() {
        console.log("Completing async operation for " + value);
        callback(value * 2);
    }, Math.floor(Math.random() * 200));
}
.as-console-wrapper { max-height: 100% !important; }

不起作用的原因是 dosomethingsasync 的回调尚未在尝试使用结果时运行。

因此,如果您有一个数组(或某种形式的列表),并且想对每个条目进行异步操作,则有两个选项:并行执行操作(重叠)或串联(一个接一个地,顺序)。

并行

您可以启动所有这些,并跟踪您期望多少回调,然后在收到许多回调时使用结果:

var results = [];
var expecting = theArray.length;
theArray.forEach(function(entry, index) {
    doSomethingAsync(entry, function(result) {
        results[index] = result;
        if (--expecting === 0) {
            // Done!
            console.log("Results:", results); // E.g., using the results
        }
    });
});

示例:

var theArray = [1, 2, 3];
var results = [];
var expecting = theArray.length;
theArray.forEach(function(entry, index) {
    doSomethingAsync(entry, function(result) {
        results[index] = result;
        if (--expecting === 0) {
            // Done!
            console.log("Results:", JSON.stringify(results)); // E.g., using the results
        }
    });
});

function doSomethingAsync(value, callback) {
    console.log("Starting async operation for " + value);
    setTimeout(function() {
        console.log("Completing async operation for " + value);
        callback(value * 2);
    }, Math.floor(Math.random() * 200));
}
.as-console-wrapper { max-height: 100% !important; }

(我们可以消除期望,只使用 result.length === thearray.length ,但这使我们对 thearray的可能性开放在呼叫未偿的时候更改...)

请注意我们如何使用 index for foreach 将结果保存在结果中在与其所关联的条目相同的位置,即使结果取出订单(由于异步调用不一定要按照启动的顺序完成)。

但是,如果您需要返回 这些结果来自函数呢?正如其他答案所指出的,您不能;您必须接受函数接受并致电回调(或返回a 承诺)。这是回调版本:

function doSomethingWith(theArray, callback) {
    var results = [];
    var expecting = theArray.length;
    theArray.forEach(function(entry, index) {
        doSomethingAsync(entry, function(result) {
            results[index] = result;
            if (--expecting === 0) {
                // Done!
                callback(results);
            }
        });
    });
}
doSomethingWith(theArray, function(results) {
    console.log("Results:", results);
});

示例:

function doSomethingWith(theArray, callback) {
    var results = [];
    var expecting = theArray.length;
    theArray.forEach(function(entry, index) {
        doSomethingAsync(entry, function(result) {
            results[index] = result;
            if (--expecting === 0) {
                // Done!
                callback(results);
            }
        });
    });
}
doSomethingWith([1, 2, 3], function(results) {
    console.log("Results:", JSON.stringify(results));
});

function doSomethingAsync(value, callback) {
    console.log("Starting async operation for " + value);
    setTimeout(function() {
        console.log("Completing async operation for " + value);
        callback(value * 2);
    }, Math.floor(Math.random() * 200));
}
.as-console-wrapper { max-height: 100% !important; }

或以下是返回 Promise 的版本:

function doSomethingWith(theArray) {
    return new Promise(function(resolve) {
        var results = [];
        var expecting = theArray.length;
        theArray.forEach(function(entry, index) {
            doSomethingAsync(entry, function(result) {
                results[index] = result;
                if (--expecting === 0) {
                    // Done!
                    resolve(results);
                }
            });
        });
    });
}
doSomethingWith(theArray).then(function(results) {
    console.log("Results:", results);
});

当然,如果 dosomethingsasync 传递了我们的错误,我们将使用 recept> recood 拒绝当我们遇到错误时承诺。)

示例:

function doSomethingWith(theArray) {
    return new Promise(function(resolve) {
        var results = [];
        var expecting = theArray.length;
        theArray.forEach(function(entry, index) {
            doSomethingAsync(entry, function(result) {
                results[index] = result;
                if (--expecting === 0) {
                    // Done!
                    resolve(results);
                }
            });
        });
    });
}
doSomethingWith([1, 2, 3]).then(function(results) {
    console.log("Results:", JSON.stringify(results));
});

function doSomethingAsync(value, callback) {
    console.log("Starting async operation for " + value);
    setTimeout(function() {
        console.log("Completing async operation for " + value);
        callback(value * 2);
    }, Math.floor(Math.random() * 200));
}
.as-console-wrapper { max-height: 100% !important; }

(或者,或者,您可以为返回承诺的 dosomethingsasync 制作包装器,然后执行以下...

) a promise =“ https://developer.mozilla.org/en-us/docs/web/javascript/reference/global_objects/promise/promise/all” rel =“ noreferrer”> promise> Promise> Promise.promise.all

function doSomethingWith(theArray) {
    return Promise.all(theArray.map(function(entry) {
        return doSomethingAsync(entry);
    }));
}
doSomethingWith(theArray).then(function(results) {
    console.log("Results:", results);
});

如果您知道 DosomethingAsync 将忽略第二个和第三个参数,则可以将其直接传递给 MAP MAP 用三个调用其回调争论,但大多数人大多数时候只使用第一次):

function doSomethingWith(theArray) {
    return Promise.all(theArray.map(doSomethingAsync));
}
doSomethingWith(theArray).then(function(results) {
    console.log("Results:", results);
});

示例:

function doSomethingWith(theArray) {
    return Promise.all(theArray.map(doSomethingAsync));
}
doSomethingWith([1, 2, 3]).then(function(results) {
    console.log("Results:", JSON.stringify(results));
});

function doSomethingAsync(value) {
    console.log("Starting async operation for " + value);
    return new Promise(function(resolve) {
        setTimeout(function() {
            console.log("Completing async operation for " + value);
            resolve(value * 2);
        }, Math.floor(Math.random() * 200));
    });
}
.as-console-wrapper { max-height: 100% !important; }

请注意, Promise.All 通过所有诺言的结果来解决其承诺,当他们全部解决时,您给予的承诺,或者在 first of时拒绝其承诺您给予的承诺拒绝。

系列

假设您不希望操作并行?如果您想一个接一个地运行它们,则需要等待每个操作完成下一个操作。这是一个可以执行此操作并调用结果的函数的示例:

function doSomethingWith(theArray, callback) {
    var results = [];
    doOne(0);
    function doOne(index) {
        if (index < theArray.length) {
            doSomethingAsync(theArray[index], function(result) {
                results.push(result);
                doOne(index + 1);
            });
        } else {
            // Done!
            callback(results);
        }
    }
}
doSomethingWith(theArray, function(results) {
    console.log("Results:", results);
});

(由于我们正在串联进行工作,因此我们可以使用 results.push(result)(result),因为我们知道我们不会在上面的订单中获得结果。 )

示例:

function doSomethingWith(theArray, callback) {
    var results = [];
    doOne(0);
    function doOne(index) {
        if (index < theArray.length) {
            doSomethingAsync(theArray[index], function(result) {
                results.push(result);
                doOne(index + 1);
            });
        } else {
            // Done!
            callback(results);
        }
    }
}
doSomethingWith([1, 2, 3], function(results) {
    console.log("Results:", JSON.stringify(results));
});

function doSomethingAsync(value, callback) {
    console.log("Starting async operation for " + value);
    setTimeout(function() {
        console.log("Completing async operation for " + value);
        callback(value * 2);
    }, Math.floor(Math.random() * 200));
}
.as-console-wrapper { max-height: 100% !important; }

(或者,再次为 dosomethingsasync 构建一个包装器,可以给您一个承诺,并做下面...)

如果 Dosomething> ,如果您可以使用ES2017+语法(也许与 babel ),您可以使用 async ruction> function with for of of of 等待等待

async function doSomethingWith(theArray) {
    const results = [];
    for (const entry of theArray) {
        results.push(await doSomethingAsync(entry));
    }
    return results;
}
doSomethingWith(theArray).then(results => {
    console.log("Results:", results);
});

例子:

async function doSomethingWith(theArray) {
    const results = [];
    for (const entry of theArray) {
        results.push(await doSomethingAsync(entry));
    }
    return results;
}
doSomethingWith([1, 2, 3]).then(function(results) {
    console.log("Results:", JSON.stringify(results));
});

function doSomethingAsync(value) {
    console.log("Starting async operation for " + value);
    return new Promise(function(resolve) {
        setTimeout(function() {
            console.log("Completing async operation for " + value);
            resolve(value * 2);
        }, Math.floor(Math.random() * 200));
    });
}
.as-console-wrapper { max-height: 100% !important; }

If you can't use ES2017+ syntax (yet), you can use a variation on the

function doSomethingWith(theArray) {
    return theArray.reduce(function(p, entry) {
        return p.then(function(results) {
            return doSomethingAsync(entry).then(function(result) {
                results.push(result);
                return results;
            });
        });
    }, Promise.resolve([]));
}
doSomethingWith(theArray).then(function(results) {
    console.log("Results:", results);
});

示例:示例:

function doSomethingWith(theArray) {
    return theArray.reduce(function(p, entry) {
        return p.then(function(results) {
            return doSomethingAsync(entry).then(function(result) {
                results.push(result);
                return results;
            });
        });
    }, Promise.resolve([]));
}
doSomethingWith([1, 2, 3]).then(function(results) {
    console.log("Results:", JSON.stringify(results));
});

function doSomethingAsync(value) {
    console.log("Starting async operation for " + value);
    return new Promise(function(resolve) {
        setTimeout(function() {
            console.log("Completing async operation for " + value);
            resolve(value * 2);
        }, Math.floor(Math.random() * 200));
    });
}
.as-console-wrapper { max-height: 100% !important; }

...与

function doSomethingWith(theArray) {
    return theArray.reduce((p, entry) => p.then(results => doSomethingAsync(entry).then(result => {
        results.push(result);
        return results;
    })), Promise.resolve([]));
}
doSomethingWith(theArray).then(results => {
    console.log("Results:", results);
});

示例:

function doSomethingWith(theArray) {
    return theArray.reduce((p, entry) => p.then(results => doSomethingAsync(entry).then(result => {
        results.push(result);
        return results;
    })), Promise.resolve([]));
}
doSomethingWith([1, 2, 3]).then(function(results) {
    console.log("Results:", JSON.stringify(results));
});

function doSomethingAsync(value) {
    console.log("Starting async operation for " + value);
    return new Promise(function(resolve) {
        setTimeout(function() {
            console.log("Completing async operation for " + value);
            resolve(value * 2);
        }, Math.floor(Math.random() * 200));
    });
}
.as-console-wrapper { max-height: 100% !important; }

Most of the answers here give useful suggestions for when you have a single async operation, but sometimes, this comes up when you need to do an asynchronous operation for each entry in an array or other list-like structure. The temptation is to do this:

// WRONG
var results = [];
theArray.forEach(function(entry) {
    doSomethingAsync(entry, function(result) {
        results.push(result);
    });
});
console.log(results); // E.g., using them, returning them, etc.

Example:

// WRONG
var theArray = [1, 2, 3];
var results = [];
theArray.forEach(function(entry) {
    doSomethingAsync(entry, function(result) {
        results.push(result);
    });
});
console.log("Results:", results); // E.g., using them, returning them, etc.

function doSomethingAsync(value, callback) {
    console.log("Starting async operation for " + value);
    setTimeout(function() {
        console.log("Completing async operation for " + value);
        callback(value * 2);
    }, Math.floor(Math.random() * 200));
}
.as-console-wrapper { max-height: 100% !important; }

The reason that doesn't work is that the callbacks from doSomethingAsync haven't run yet by the time you're trying to use the results.

So, if you have an array (or list of some kind) and want to do async operations for each entry, you have two options: Do the operations in parallel (overlapping), or in series (one after another in sequence).

Parallel

You can start all of them and keep track of how many callbacks you're expecting, and then use the results when you've gotten that many callbacks:

var results = [];
var expecting = theArray.length;
theArray.forEach(function(entry, index) {
    doSomethingAsync(entry, function(result) {
        results[index] = result;
        if (--expecting === 0) {
            // Done!
            console.log("Results:", results); // E.g., using the results
        }
    });
});

Example:

var theArray = [1, 2, 3];
var results = [];
var expecting = theArray.length;
theArray.forEach(function(entry, index) {
    doSomethingAsync(entry, function(result) {
        results[index] = result;
        if (--expecting === 0) {
            // Done!
            console.log("Results:", JSON.stringify(results)); // E.g., using the results
        }
    });
});

function doSomethingAsync(value, callback) {
    console.log("Starting async operation for " + value);
    setTimeout(function() {
        console.log("Completing async operation for " + value);
        callback(value * 2);
    }, Math.floor(Math.random() * 200));
}
.as-console-wrapper { max-height: 100% !important; }

(We could do away with expecting and just use results.length === theArray.length, but that leaves us open to the possibility that theArray is changed while the calls are outstanding...)

Notice how we use the index from forEach to save the result in results in the same position as the entry it relates to, even if the results arrive out of order (since async calls don't necessarily complete in the order in which they were started).

But what if you need to return those results from a function? As the other answers have pointed out, you can't; you have to have your function accept and call a callback (or return a Promise). Here's a callback version:

function doSomethingWith(theArray, callback) {
    var results = [];
    var expecting = theArray.length;
    theArray.forEach(function(entry, index) {
        doSomethingAsync(entry, function(result) {
            results[index] = result;
            if (--expecting === 0) {
                // Done!
                callback(results);
            }
        });
    });
}
doSomethingWith(theArray, function(results) {
    console.log("Results:", results);
});

Example:

function doSomethingWith(theArray, callback) {
    var results = [];
    var expecting = theArray.length;
    theArray.forEach(function(entry, index) {
        doSomethingAsync(entry, function(result) {
            results[index] = result;
            if (--expecting === 0) {
                // Done!
                callback(results);
            }
        });
    });
}
doSomethingWith([1, 2, 3], function(results) {
    console.log("Results:", JSON.stringify(results));
});

function doSomethingAsync(value, callback) {
    console.log("Starting async operation for " + value);
    setTimeout(function() {
        console.log("Completing async operation for " + value);
        callback(value * 2);
    }, Math.floor(Math.random() * 200));
}
.as-console-wrapper { max-height: 100% !important; }

Or here's a version returning a Promise instead:

function doSomethingWith(theArray) {
    return new Promise(function(resolve) {
        var results = [];
        var expecting = theArray.length;
        theArray.forEach(function(entry, index) {
            doSomethingAsync(entry, function(result) {
                results[index] = result;
                if (--expecting === 0) {
                    // Done!
                    resolve(results);
                }
            });
        });
    });
}
doSomethingWith(theArray).then(function(results) {
    console.log("Results:", results);
});

Of course, if doSomethingAsync passed us errors, we'd use reject to reject the promise when we got an error.)

Example:

function doSomethingWith(theArray) {
    return new Promise(function(resolve) {
        var results = [];
        var expecting = theArray.length;
        theArray.forEach(function(entry, index) {
            doSomethingAsync(entry, function(result) {
                results[index] = result;
                if (--expecting === 0) {
                    // Done!
                    resolve(results);
                }
            });
        });
    });
}
doSomethingWith([1, 2, 3]).then(function(results) {
    console.log("Results:", JSON.stringify(results));
});

function doSomethingAsync(value, callback) {
    console.log("Starting async operation for " + value);
    setTimeout(function() {
        console.log("Completing async operation for " + value);
        callback(value * 2);
    }, Math.floor(Math.random() * 200));
}
.as-console-wrapper { max-height: 100% !important; }

(Or alternately, you could make a wrapper for doSomethingAsync that returns a promise, and then do the below...)

If doSomethingAsync gives you a Promise, you can use Promise.all:

function doSomethingWith(theArray) {
    return Promise.all(theArray.map(function(entry) {
        return doSomethingAsync(entry);
    }));
}
doSomethingWith(theArray).then(function(results) {
    console.log("Results:", results);
});

If you know that doSomethingAsync will ignore a second and third argument, you can just pass it directly to map (map calls its callback with three arguments, but most people only use the first most of the time):

function doSomethingWith(theArray) {
    return Promise.all(theArray.map(doSomethingAsync));
}
doSomethingWith(theArray).then(function(results) {
    console.log("Results:", results);
});

Example:

function doSomethingWith(theArray) {
    return Promise.all(theArray.map(doSomethingAsync));
}
doSomethingWith([1, 2, 3]).then(function(results) {
    console.log("Results:", JSON.stringify(results));
});

function doSomethingAsync(value) {
    console.log("Starting async operation for " + value);
    return new Promise(function(resolve) {
        setTimeout(function() {
            console.log("Completing async operation for " + value);
            resolve(value * 2);
        }, Math.floor(Math.random() * 200));
    });
}
.as-console-wrapper { max-height: 100% !important; }

Note that Promise.all resolves its promise with an array of the results of all of the promises you give it when they are all resolved, or rejects its promise when the first of the promises you give it rejects.

Series

Suppose you don't want the operations to be in parallel? If you want to run them one after another, you need to wait for each operation to complete before you start the next. Here's an example of a function that does that and calls a callback with the result:

function doSomethingWith(theArray, callback) {
    var results = [];
    doOne(0);
    function doOne(index) {
        if (index < theArray.length) {
            doSomethingAsync(theArray[index], function(result) {
                results.push(result);
                doOne(index + 1);
            });
        } else {
            // Done!
            callback(results);
        }
    }
}
doSomethingWith(theArray, function(results) {
    console.log("Results:", results);
});

(Since we're doing the work in series, we can just use results.push(result) since we know we won't get results out of order. In the above we could have used results[index] = result;, but in some of the following examples we don't have an index to use.)

Example:

function doSomethingWith(theArray, callback) {
    var results = [];
    doOne(0);
    function doOne(index) {
        if (index < theArray.length) {
            doSomethingAsync(theArray[index], function(result) {
                results.push(result);
                doOne(index + 1);
            });
        } else {
            // Done!
            callback(results);
        }
    }
}
doSomethingWith([1, 2, 3], function(results) {
    console.log("Results:", JSON.stringify(results));
});

function doSomethingAsync(value, callback) {
    console.log("Starting async operation for " + value);
    setTimeout(function() {
        console.log("Completing async operation for " + value);
        callback(value * 2);
    }, Math.floor(Math.random() * 200));
}
.as-console-wrapper { max-height: 100% !important; }

(Or, again, build a wrapper for doSomethingAsync that gives you a promise and do the below...)

If doSomethingAsync gives you a Promise, if you can use ES2017+ syntax (perhaps with a transpiler like Babel), you can use an async function with for-of and await:

async function doSomethingWith(theArray) {
    const results = [];
    for (const entry of theArray) {
        results.push(await doSomethingAsync(entry));
    }
    return results;
}
doSomethingWith(theArray).then(results => {
    console.log("Results:", results);
});

Example:

async function doSomethingWith(theArray) {
    const results = [];
    for (const entry of theArray) {
        results.push(await doSomethingAsync(entry));
    }
    return results;
}
doSomethingWith([1, 2, 3]).then(function(results) {
    console.log("Results:", JSON.stringify(results));
});

function doSomethingAsync(value) {
    console.log("Starting async operation for " + value);
    return new Promise(function(resolve) {
        setTimeout(function() {
            console.log("Completing async operation for " + value);
            resolve(value * 2);
        }, Math.floor(Math.random() * 200));
    });
}
.as-console-wrapper { max-height: 100% !important; }

If you can't use ES2017+ syntax (yet), you can use a variation on the "Promise reduce" pattern (this is more complex than the usual Promise reduce because we're not passing the result from one into the next, but instead gathering up their results in an array):

function doSomethingWith(theArray) {
    return theArray.reduce(function(p, entry) {
        return p.then(function(results) {
            return doSomethingAsync(entry).then(function(result) {
                results.push(result);
                return results;
            });
        });
    }, Promise.resolve([]));
}
doSomethingWith(theArray).then(function(results) {
    console.log("Results:", results);
});

Example:

function doSomethingWith(theArray) {
    return theArray.reduce(function(p, entry) {
        return p.then(function(results) {
            return doSomethingAsync(entry).then(function(result) {
                results.push(result);
                return results;
            });
        });
    }, Promise.resolve([]));
}
doSomethingWith([1, 2, 3]).then(function(results) {
    console.log("Results:", JSON.stringify(results));
});

function doSomethingAsync(value) {
    console.log("Starting async operation for " + value);
    return new Promise(function(resolve) {
        setTimeout(function() {
            console.log("Completing async operation for " + value);
            resolve(value * 2);
        }, Math.floor(Math.random() * 200));
    });
}
.as-console-wrapper { max-height: 100% !important; }

...which is less cumbersome with ES2015+ arrow functions:

function doSomethingWith(theArray) {
    return theArray.reduce((p, entry) => p.then(results => doSomethingAsync(entry).then(result => {
        results.push(result);
        return results;
    })), Promise.resolve([]));
}
doSomethingWith(theArray).then(results => {
    console.log("Results:", results);
});

Example:

function doSomethingWith(theArray) {
    return theArray.reduce((p, entry) => p.then(results => doSomethingAsync(entry).then(result => {
        results.push(result);
        return results;
    })), Promise.resolve([]));
}
doSomethingWith([1, 2, 3]).then(function(results) {
    console.log("Results:", JSON.stringify(results));
});

function doSomethingAsync(value) {
    console.log("Starting async operation for " + value);
    return new Promise(function(resolve) {
        setTimeout(function() {
            console.log("Completing async operation for " + value);
            resolve(value * 2);
        }, Math.floor(Math.random() * 200));
    });
}
.as-console-wrapper { max-height: 100% !important; }

如何从异步电话中返回响应?

浅紫色的梦幻 2025-02-18 07:03:40

您需要检查所读的行,而不是 logFile 实例

with open(NR_log, 'r') as logfile:
    lines = [line.strip() for line in logfile.readlines()]
    if name_key not in lines:
        lst.append('\nError: Script was not successfully executed.\n')
    ....

You need to check the lines you read, not the logfile instance

with open(NR_log, 'r') as logfile:
    lines = [line.strip() for line in logfile.readlines()]
    if name_key not in lines:
        lst.append('\nError: Script was not successfully executed.\n')
    ....

通过python寻找文件中的字符串总是失败

浅紫色的梦幻 2025-02-18 04:54:17

好吧,我刚刚找到解决方案 emore 。基本上,您需要强迫Slack在调用 views_update()时给出新的块ID来重建UI元素(在这种情况下为文本输入字段)。

然后,初始值被用来填充文本输入,从而解决了我的问题。

Okay i just found the solution here. Basically you need to force slack to rebuild the ui element (in this case the text input field) by giving it a new block id when calling views_update().

Then the initial value gets used to fill the text input thus solving my issue.

Slack Block套件纯文本输入元素更新文本值

浅紫色的梦幻 2025-02-18 01:53:24

您可以使用替换 method ='ffill'为每个组:

out = df.groupby(level=0).apply(lambda x: x.replace(0, method='ffill'))
print(out)

# Output
        0   1  2  3
0 0     0   0  0  0
  1    36  19  2  4
  2   233  21  2  4
  3   505  25  1  4
  4   751  27  1  4
  5   976  28  1  4
  9   976  28  1  4
  10  976  28  1  4
  11  976  28  1  4
  12  976  28  1  4
1 0    40  19  2  4
  1   323  18  1  4
  2   595  24  1  4
  3   844  26  1  4
  4   844  26  1  4
  5   844  26  1  4
  9   844  26  1  4
  10  844  26  1  4
  11  844  26  1  4
  12  844  26  1  4

You can use replace with method='ffill' for each group:

out = df.groupby(level=0).apply(lambda x: x.replace(0, method='ffill'))
print(out)

# Output
        0   1  2  3
0 0     0   0  0  0
  1    36  19  2  4
  2   233  21  2  4
  3   505  25  1  4
  4   751  27  1  4
  5   976  28  1  4
  9   976  28  1  4
  10  976  28  1  4
  11  976  28  1  4
  12  976  28  1  4
1 0    40  19  2  4
  1   323  18  1  4
  2   595  24  1  4
  3   844  26  1  4
  4   844  26  1  4
  5   844  26  1  4
  9   844  26  1  4
  10  844  26  1  4
  11  844  26  1  4
  12  844  26  1  4

用多索引数据框架上的每列替换最后一个非零值的零值

浅紫色的梦幻 2025-02-17 22:07:52

我认为我设法在Ryan Dawson的帮助下做出了另一种诊断方法。
我确实在当地的后端POD Portforaward并从本地请求,然后发现有一个500错误代码 - &gt;这意味着该请求与API要求不符合:在前端我是错误的上下文类型。

- &gt;因此,入口配置已经处于良好状态。

I thinks that I managed to make another Diagnotic method wiht the help for Ryan Dawson.
I did PortForaward the backend pod and request from the locally, then I found that there is a 500 error code --> meaning that the request was not matching the api requirements: in the frontend I was sendign the wrong context type.

--> so the ingress config is already in a good shape.

启用端点404错误代码 - 部署的应用程序

浅紫色的梦幻 2025-02-17 13:19:04

我们可以使用单元格样式的背景图像属性将图像插入PDFGrid中。它正确地在网格单元中添加了图像。请找到以下代码段,

PdfDocument document = PdfDocument();

//Create a PdfGrid class

PdfGrid grid = PdfGrid();

//Add the columns to the grid

grid.columns.add(count: 3);

//Add header to the grid

grid.headers.add(1);

//Add the rows to the grid

PdfGridRow header = grid.headers[0];

header.cells[0].value = 'Employee ID';

header.cells[1].value = 'Employee Name';

header.cells[2].value = 'Salary';

//Add rows to grid

PdfGridRow row = grid.rows.add();

row.cells[0].value = 'E01';

row.cells[1].value = 'Clay';

row.cells[2].value = '\$10,000';

final PdfImage image = PdfBitmap(File('E://logo.png').readAsBytesSync());

row = grid.rows.add();

row.height = 30;

row.cells[0].value = 'E02';

row.cells[1].style.backgroundImage = image;

row.cells[1].value = "";

row.cells[2].value = '\$12,000';

row = grid.rows.add();

row.cells[0].value = 'E03';

row.cells[1].value = 'John';

row.cells[2].value = '\$14,000';

//Draw the grid

grid.draw(
      page: document.pages.add(), bounds: const Rect.fromLTWH(0, 0, 0, 0));

File('E://Flutter/GridOutput.pdf').writeAsBytes(document.save());

document.dispose();

示例:

ug:

​https://help.syncfusion.com/flutter/pdf/working-with-tables

We can insert an image into the PdfGrid by using the BackgroundImage property in the Cell style. Its added a image in a grid cell properly. Please find the below code snippet,

PdfDocument document = PdfDocument();

//Create a PdfGrid class

PdfGrid grid = PdfGrid();

//Add the columns to the grid

grid.columns.add(count: 3);

//Add header to the grid

grid.headers.add(1);

//Add the rows to the grid

PdfGridRow header = grid.headers[0];

header.cells[0].value = 'Employee ID';

header.cells[1].value = 'Employee Name';

header.cells[2].value = 'Salary';

//Add rows to grid

PdfGridRow row = grid.rows.add();

row.cells[0].value = 'E01';

row.cells[1].value = 'Clay';

row.cells[2].value = '\$10,000';

final PdfImage image = PdfBitmap(File('E://logo.png').readAsBytesSync());

row = grid.rows.add();

row.height = 30;

row.cells[0].value = 'E02';

row.cells[1].style.backgroundImage = image;

row.cells[1].value = "";

row.cells[2].value = '\$12,000';

row = grid.rows.add();

row.cells[0].value = 'E03';

row.cells[1].value = 'John';

row.cells[2].value = '\$14,000';

//Draw the grid

grid.draw(
      page: document.pages.add(), bounds: const Rect.fromLTWH(0, 0, 0, 0));

File('E://Flutter/GridOutput.pdf').writeAsBytes(document.save());

document.dispose();

Sample:
https://www.syncfusion.com/downloads/support/directtrac/general/pd/GridOutput921468422

UG: https://help.syncfusion.com/flutter/pdf/working-with-images

Tables: https://help.syncfusion.com/flutter/pdf/working-with-tables

如何在PDFGrid中插入图像?扑

浅紫色的梦幻 2025-02-17 13:17:06

如果您在Django设置中已安装的应用程序中注册应用程序名称,则可以轻松处理大多数迁移和其他方面的其他内容,您可以从应用程序名称的文件夹中分支。
制作一个名为应用程序的单独目录,您可以将所有应用程序放置在应用程序主管中

我建议您

from app.some_new_app_name.models import MyModel
from app.some_new_app_name_2.models import MyModel2

If you register the app name in installed app in django settings you can easily handle most migrations and other stuff other wise you can just branch off from the folder of the app name.
What i recommend is making a separate directory named app and you can place all your app inside app director so the app and project directory gets separated easily and your import will also be easy

you can import in this manner after wards

from app.some_new_app_name.models import MyModel
from app.some_new_app_name_2.models import MyModel2

Django如何处理应用程序的导入?

浅紫色的梦幻 2025-02-17 10:12:37

尝试以下操作:

function scoreToGrade() {
  var cellsChecked = ['AF2', 'AG2', 'AH2'];
  var sheet = SpreadsheetApp.getActiveSheet();
  for (var i = 0; i < cellsChecked.length; i++) {
    var value = sheet.getRange(cellsChecked[i]).getDisplayValue();
    console.log(value);
    if (value == '#VALUE!') {
      // do something
      console.log('Not blank ' + value);
      sheet.deleteColumn(sheet.getRange(cellsChecked[i]).getColumn());
    } else {
      // do something else
      console.log('is another value ' + value);
    }
  }
}

Try this:

function scoreToGrade() {
  var cellsChecked = ['AF2', 'AG2', 'AH2'];
  var sheet = SpreadsheetApp.getActiveSheet();
  for (var i = 0; i < cellsChecked.length; i++) {
    var value = sheet.getRange(cellsChecked[i]).getDisplayValue();
    console.log(value);
    if (value == '#VALUE!') {
      // do something
      console.log('Not blank ' + value);
      sheet.deleteColumn(sheet.getRange(cellsChecked[i]).getColumn());
    } else {
      // do something else
      console.log('is another value ' + value);
    }
  }
}

Google AppScript检查单元格值和删除列

更多

推荐作者

櫻之舞

文章 0 评论 0

弥枳

文章 0 评论 0

m2429

文章 0 评论 0

野却迷人

文章 0 评论 0

我怀念的。

文章 0 评论 0

更多

友情链接

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文