我正在尝试使用 node.js 编写一个不和谐的机器人,但是我在使用 messageReactionAdd 时遇到了问题我现在不知道为什么当我对表情符号做出反应时机器人什么都不做。
我的代码:
bot.on('messageReactionRemove', (reaction, user) => {
console.log("that work 1");
if(reaction.emoji.name === "white_check_mark") {
console.log("that work 2");
}})
Run Code Online (Sandbox Code Playgroud) 在我的代码中table_df有一些列,我正在对这些列进行一些计算,例如 min、max、mean 等,并且我想创建具有指定架构 new_df_schema 的 new_df。在我的逻辑中,我编写了用于计算的 spark-sql,并将每个新生成的行附加到最初为空的 new_df 中,最后,它会生成new_df所有列的所有计算值。
但问题是当列数更多时会导致性能问题。这可以在不使用 union() 函数或任何其他提高性能的方法的情况下完成吗?
import org.apache.spark.sql.Row
import org.apache.spark.sql.types._
import org.apache.spark.sql.functions._
import sparkSession.sqlContext.implicits._
val table_df = Seq(
(10, 20, 30, 40, 50),
(100, 200, 300, 400, 500),
(111, 222, 333, 444, 555),
(1123, 2123, 3123, 4123, 5123),
(1321, 2321, 3321, 4321, 5321)
).toDF("col_1", "col_2", "col_3", "col_4", "col_5")
table_df.show(false)
table_df.createOrReplaceTempView("table_df")
val new_df_schema = StructType(
StructField("Column_Name", StringType, false) ::
StructField("number_of_values", LongType, false) ::
StructField("number_of_distinct_values", LongType, false) ::
StructField("distinct_count_with_nan", LongType, false) :: …Run Code Online (Sandbox Code Playgroud) 我使用了一个函数,它以交互方式从用户那里获取一些输入并返回一些值。我想运行该函数(不更改它)而不必自己输入值,例如从列表中读取它。我怎样才能做到这一点?
MCVE:
def add():
a = int(input('first number: '))
b = int(input('first number: '))
return(a+b)
Run Code Online (Sandbox Code Playgroud)
我希望能够运行类似magic(add(), [2, 3])获取输出的东西5。
我正在建造一个用于脑分流的滴水监测器原型。它将监控滴注并报告我需要的任何数据。问题是我只是在构建设备。一个对 Arduino 或代码一无所知的人正在使用它。有没有一种方法或程序可以显示数据和/或将数据保存到文件中,以便人们只需插入 Arduino 而无需打扰 IDE 或任何代码?
这里是 python 新手。我想创建一个脚本来扫描我的目录,如果文件名中包含特定字符串,那么它将自动移动到我选择的文件夹。已经尝试过这个,但没有运气:
import os
import shutil
import fnmatch
import glob
ffe_path = 'E:/FFE'
new_path = 'E:/FFE/Membership/letters'
keyword = 'membership'
os.chdir('E:/FFE/Membership')
os.mkdir('letters')
source_dir = 'E:/FFE'
dest_dir = 'E:/FFE/Membership/letters'
os.chdir(source_dir)
for top, dirs, files in os.walk(source_dir):
for filename in files:
if not filename.endswith('.docx'):
continue
file_path = os.path.join(top, filename)
with open(file_path, 'r') as f:
if '*membership' in f.read():
shutil.move(file_path, os.path.join(dest_dir, filename))
Run Code Online (Sandbox Code Playgroud)
任何见解将不胜感激。
第一次海报和最近在python 上自学的初学者。
我查了有关堆栈溢出的问题,但没有看到完全相同的内容。我想遍历整个列表,如果某个项目满足条件,则将其弹出到不同的列表中。使用 for 循环不起作用,因为一旦删除了一个项目,列表中就没有足够的项目来完成初始范围。我写了这段代码(使用 while 的伪 for 循环),我认为它可以正常工作,但想知道它是否正确,或者是否有更好/更优雅/更有效的方法?
while i < len(mylist):
if mylist[i] > 12:
mydiscard.append(mylist.pop(i))
continue
i+=1
Run Code Online (Sandbox Code Playgroud) 我想将“Enter”键仅绑定到其中一个选项卡,这是示例代码
from tkinter import *
from tkinter import ttk
def hello(event):
print('hello')
window = Tk()
window.geometry('500x500')
tab_control = ttk.Notebook(window)
tab_1 = ttk.Frame(tab_control)
tab_2 = ttk.Frame(tab_control)
tab_control.add(tab_1, text='Tab 1')
tab_control.add(tab_2, text='Tab 2')
tab_control.pack(expand=1, fill='both')
window.bind('<Return>', hello)
window.mainloop()
Run Code Online (Sandbox Code Playgroud)
window.bind()将允许用户在两个选项卡中运行hello()功能。但我只想将它绑定到tab_1.
我尝试过tab_1.bind('<Return>', hello),但两个选项卡中都没有任何响应。
示例输入:s = "abcabcbb" 输出:3 解释:答案是“abc”,长度为 3。我试着写这个,但如果条件永远不会被执行。我无法弄清楚原因。
var lengthOfLongestSubstring = function(s) {
let set = new Set();
let c =0;
for(let i =0; i< s.length; i++){
if(set.has(s[i])){
set.size =0;
}
else {
console.log(c)
c++;
}
}
return c;
};
console.log(lengthOfLongestSubstring("abcabcbb"))Run Code Online (Sandbox Code Playgroud)
更新 09/17/2012
这是一段使用自包含数据重现我的问题的代码:
请记住,我拥有的实际数据维度很大......
尺寸:3105、7025、21812625、12(nrow、ncol、ncell、nlayers)
我需要的是每一行的最大值的索引,层上的列。所有 NA 都应该返回 NA 并且多个最大副本应该返回第一个最大索引(或其他东西,必须一致)
# Create a test RasterStack
require(raster)
a <- raster(matrix(c(11,11,11,
NA,11,11,
11,11,13),nrow=3))
b <- raster(matrix(c(12,12,12,
NA,12,12,
40,12,13),nrow=3))
c <- raster(matrix(c(13,9,13,
NA,13,13,
13,NA,13),nrow=3))
d <- raster(matrix(c(10,10,10,
NA,10,10,
10,10,10),nrow=3))
corr_max <- raster(matrix(c(13,12,13,
NA,13,13,
40,12,13),nrow=3))
stack <- stack(a,b,c,d)
which.max2 <- function(x, ...)which.max(x)
# stackApply method
max_v_sApp <- stackApply(stack,rep(1,4),which.max2,na.rm=NULL)
# calc method
max_v_calc <- calc(stack,which.max)
Run Code Online (Sandbox Code Playgroud)
希望这提供了足够的信息。
更新:
这可能有效......现在测试:
which.max2 <- function(x, ...){
max_idx <- which.max(x) # Get the max
ifelse(length(max_idx)==0,return(NA),return(max_idx))
}
Run Code Online (Sandbox Code Playgroud) python ×4
javascript ×2
algorithm ×1
apache-spark ×1
apply ×1
arduino ×1
discord.js ×1
fnmatch ×1
input ×1
list ×1
loops ×1
max ×1
monitor ×1
python-3.x ×1
python-os ×1
r ×1
raster ×1
shutil ×1
tkinter ×1