一念一轮回

文章 评论 浏览 30

一念一轮回 2025-02-11 20:18:14

可能会有所帮助。

var result = (from a in Enumerable.Range(0, n - 1)
              from b in Enumerable.Range(a + 1, n - a - 1)
              select Tuple.Create(a, b)).ToList();

It could be helpfull.

var result = (from a in Enumerable.Range(0, n - 1)
              from b in Enumerable.Range(a + 1, n - a - 1)
              select Tuple.Create(a, b)).ToList();

如何将嵌套循环转换为LINQ-Statement?

一念一轮回 2025-02-11 18:33:15

您正在将整个计划置于监狱中,而不仅仅是子过程。使用 preexec_fn ,因此只有子过程在监狱中,而不是python程序的其余部分,然后您将在 chroot_path 目录中找到输出文件:目录:

import os, subprocess

class Jailer(object):
    def __init__(self, chroot_path):
        self.chroot_path = chroot_path
    def __call__(self):
        os.chdir(self.chroot_path)
        os.chroot(self.chroot_path)

def run_valgrind_in_jail(chroot_path, command):
    proc = subprocess.run(['valgrind', '--xml=yes','--leak-check=full', '--verbose',
                           f'--xml-file={command}_valgrind.xml',
                           f'--log-file={command}_valgrind.txt',
                           command], 
                          stderr=subprocess.PIPE, stdout=subprocess.PIPE,
                          preexec_fn=Jailer(chroot_path))
    xml_file = open(os.path.join(chroot_path, f'{command}_valgrind.xml'))
    log_file = open(os.path.join(chroot_path, f'{command}_valgrind.txt'))
    return (proc, xml_file, log_file)

You're putting your whole program in jail, not just the subprocess. Use a preexec_fn so only the subprocess is in the jail, not the rest of your Python program, and then you'll find your output files in the chroot_path directory:

import os, subprocess

class Jailer(object):
    def __init__(self, chroot_path):
        self.chroot_path = chroot_path
    def __call__(self):
        os.chdir(self.chroot_path)
        os.chroot(self.chroot_path)

def run_valgrind_in_jail(chroot_path, command):
    proc = subprocess.run(['valgrind', '--xml=yes','--leak-check=full', '--verbose',
                           f'--xml-file={command}_valgrind.xml',
                           f'--log-file={command}_valgrind.txt',
                           command], 
                          stderr=subprocess.PIPE, stdout=subprocess.PIPE,
                          preexec_fn=Jailer(chroot_path))
    xml_file = open(os.path.join(chroot_path, f'{command}_valgrind.xml'))
    log_file = open(os.path.join(chroot_path, f'{command}_valgrind.txt'))
    return (proc, xml_file, log_file)

如何获得子过程中执行命令的子进程的结果?

一念一轮回 2025-02-11 10:08:50

如果您需要专业执行某个成员函数,则可以使用奇怪的是重复出现的模板模式(或简称CRTP)。然后,您将创建一个基类的基础类别。两者仅包含您要专业的特定成员函数。

template <class T, class CRTP, unsigned Capacity>
struct display_impl {
    void display() const {
        auto& This = static_cast<const CRTP&>(*this);
        // Use `This` to access members of Collection
    }
};

template <class CRTP, unsigned Capacity>
struct display_impl<Pair, CRTP, Capacity> {
    void display() const {
        auto& This = static_cast<const CRTP&>(*this);
        // Use `This` to access members of Collection
    }
};

集合现在将从 display_impl 供应本身作为模板参数:

template <class T, unsigned Capacity>
struct Collection : display_impl<T, Collection<T, Capacity>, Capacity> {
    friend struct display_impl<T, Collection<T, Capacity>, Capacity>;
};

demo

If you need to specialize a certain member function, you can use the Curiously Recurring Template Pattern (or CRTP for short). You'd then create a base class and a specialization of that base class. Both contain only the specific member function that you want to specialize.

template <class T, class CRTP, unsigned Capacity>
struct display_impl {
    void display() const {
        auto& This = static_cast<const CRTP&>(*this);
        // Use `This` to access members of Collection
    }
};

template <class CRTP, unsigned Capacity>
struct display_impl<Pair, CRTP, Capacity> {
    void display() const {
        auto& This = static_cast<const CRTP&>(*this);
        // Use `This` to access members of Collection
    }
};

Collection will now inherit from display_impl and supply itself as a template parameter:

template <class T, unsigned Capacity>
struct Collection : display_impl<T, Collection<T, Capacity>, Capacity> {
    friend struct display_impl<T, Collection<T, Capacity>, Capacity>;
};

Demo

模板专业化只有一个参数

一念一轮回 2025-02-11 07:27:35

假设您有一个dataframe df ,以及一堆列,包括趋势 PRISE 和一些水果列,例如 apples 香蕉 oranges 。您可以在感兴趣的列名上使用 lapply(),将每列馈送到一个简单函数,该功能 as.formula 创建感兴趣的公式,然后返回数据感兴趣的。这是一个exmaple:

f <- function(col,df) {
  form = as.formula(paste0("Price~s(Trend,k=2)+s(",col,",k=2)"))
  data.frame(col = col, gcv = gam(form, data = df, family="quasipoisson")$gcv)
}

现在,应用关注的功能列,并用 do.call(rbind())包装以返回一个表

do.call(rbind, lapply(c("apples","bananas", "oranges"), f, df=df))

输出:输入:

      col      gcv
1  apples 1.658002
2 bananas 1.649134
3 oranges 1.637182

输入:

set.seed(123)
df = data.frame(
  Trend = sample(1:20, 100, replace=T),
  Price = sample(30:60, 100, replace=T),
  apples = sample(5:15, 100, replace=T),
  oranges = sample(2:9, 100, replace=T),
  bananas = sample(4:8, 100, replace=T)
)

Let's say you have a dataframe df, and a bunch of columns,including Trend, Price, and some fruit columns, like apples, bananas, and oranges. You can use lapply() over the column names of interest, feeding each column to a simple function that leverages as.formula to create the formula of interest, and returns the data of interest. Here is an exmaple:

f <- function(col,df) {
  form = as.formula(paste0("Price~s(Trend,k=2)+s(",col,",k=2)"))
  data.frame(col = col, gcv = gam(form, data = df, family="quasipoisson")$gcv)
}

Now, apply the function columns of interest, and wrap in do.call(rbind()) to return a single table

do.call(rbind, lapply(c("apples","bananas", "oranges"), f, df=df))

Output:

      col      gcv
1  apples 1.658002
2 bananas 1.649134
3 oranges 1.637182

Input:

set.seed(123)
df = data.frame(
  Trend = sample(1:20, 100, replace=T),
  Price = sample(30:60, 100, replace=T),
  apples = sample(5:15, 100, replace=T),
  oranges = sample(2:9, 100, replace=T),
  bananas = sample(4:8, 100, replace=T)
)

一个变量的输入列表一次一次进入同一公式,以测试公式输出如何变化

一念一轮回 2025-02-11 06:54:38

编译器告诉您原因:

此函数的返回类型包含借用的值,但签名并未说出项目的3个寿命中的哪一种是从

借用的

从类型三个寿命>&amp; vec&lt;(&amp; str,str,usize)&gt; :&amp; /代码>。 lifetime Elision sulision ulision规则只能在返回类型时选择寿命有一个一个参数,或者如果有 self 参数,则在这种情况下它们使用其寿命。

The compiler is telling you why:

this function's return type contains a borrowed value, but the signature does not say which one of items's 3 lifetimes it is borrowed from

There are three lifetimes in the type &Vec<(&str, &str, usize)>: &'a Vec<(&'b str, &'c str, usize)>. The lifetime elision rules can only choose the lifetime for the return type when there is one parameter, or if there is a self parameter in which case they uses its lifetime.

为什么我可以在一种情况下详细介绍返回类型的寿命,而另一种情况需要明确选择寿命?

一念一轮回 2025-02-10 19:55:05

浮点符号以完全相同的方式打破了您在小学时学到的十进制(基本10)符号,并且每天使用使用,仅适用于Base-2。

要理解,考虑将2/3表示为十进制价值。完全不可能做到!世界将在您完成小数点之后写6的内容之前结束,因此,我们将其写入一些位置,将其写入最后的7个位置,并认为它足够准确。

以同样的方式,1/10(十进制为0.1)不能完全以“十进制”值表示基础2(二进制);小数点后的重复模式永远存在。该值不准确,因此您无法使用普通的浮点方法对其进行精确数学。就像基本10一样,还有其他值也表现出此问题。

Floating point notation is broken in the exact same way the decimal (base-10) notation you learned in grade school and use every day is broken, just for base-2.

To understand, think about representing 2/3 as a decimal value. It's impossible to do exactly! The world will end before you finish writing the 6's after the decimal point, and so instead we write to some number of places, round to a final 7, and consider it sufficiently accurate.

In the same way, 1/10 (decimal 0.1) cannot be represented exactly in base 2 (binary) as a "decimal" value; a repeating pattern after the decimal point goes on forever. The value is not exact, and therefore you can't do exact math with it using normal floating point methods. Just like with base 10, there are other values that exhibit this problem as well.

浮点数学破裂了吗?

一念一轮回 2025-02-10 16:58:27

我已经通过将库将库的库放回上一个,直到Microsoft通过修复程序发布下一个版本,此问题是此版本的LIB。

I had resolved the issue by reverting my library to previous one, until Microsoft releases next version with the fix, the issue was with this version of the lib

Swagger UI(Core 6.2.3的swashbuckle)没有向强制性标头抛出UI级别错误消息

一念一轮回 2025-02-10 14:20:34

您可以使用这样的多键入来确保它是一个或另一个。

functionH(data: oldTypeObject | newTypeObject) {
    if ((data as oldTypeObject).name) {
        function1(data as oldTypeObject);
    } else {
        function2(data as newTypeObject);
    }
}

虽然有点笨重,但@alexander s解决方案它是更严格的键入,它可能是您之所以追求的。

you could use a multi typing like this to ensure that it is one or the other.

functionH(data: oldTypeObject | newTypeObject) {
    if ((data as oldTypeObject).name) {
        function1(data as oldTypeObject);
    } else {
        function2(data as newTypeObject);
    }
}

While being a bit bulkier then @Alexanders solution it is the stricter typed one which might be what you are after.

如何将不同属性名称的对象传递到可以接受该参数符号的同一函数

一念一轮回 2025-02-10 03:58:35

这是给我带来理想结果的方法。

我希望这对某人有帮助

public function ImageScanner() {
    $current_dir = getcwd();
    $folderpath = 'PATH/TO/SOME/DIR/';

    // Determining if the path is a directory or not
    if (is_dir($folderpath)) {

        // Opening the directory
        $files = opendir($folderpath); {

            // Checking if the directory opened
            if ($files) {

                //Reading each element's name in the directory
                while (($subfolder = readdir($files)) !== false) {

                    // Checking for errors in filename
                    if ($subfolder != '.' && $subfolder != '..') {
                        $dirpath = 'SOME/SUB_DIR/PATH/' . $subfolder . '/';

                        // Checking and opening each file inside the sub directory
                        if (is_dir($dirpath)) {
                            $file = opendir($dirpath);
                            if ($file) {
                                
                                // Reading each element's name in the sub directory
                                while (($filename = readdir($file)) !== false) {
                                    if ($filename != '.' && $filename != '..') {
                                        $image_path = '' . $dirpath . '' . $filename . '';

                                        // Creating array for each scanned file
                                        $key = array(
                                            'image_name' => trim($filename) ,
                                            'image_path' => str_replace('/SOME/PATH/', '', $image_path) ,
                                        );

                                        // Appending each image array
                                        $image_arrays[] = $key;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    return $image_arrays;
}

This is the approach that got me the desired result.

I hope this will help someone

public function ImageScanner() {
    $current_dir = getcwd();
    $folderpath = 'PATH/TO/SOME/DIR/';

    // Determining if the path is a directory or not
    if (is_dir($folderpath)) {

        // Opening the directory
        $files = opendir($folderpath); {

            // Checking if the directory opened
            if ($files) {

                //Reading each element's name in the directory
                while (($subfolder = readdir($files)) !== false) {

                    // Checking for errors in filename
                    if ($subfolder != '.' && $subfolder != '..') {
                        $dirpath = 'SOME/SUB_DIR/PATH/' . $subfolder . '/';

                        // Checking and opening each file inside the sub directory
                        if (is_dir($dirpath)) {
                            $file = opendir($dirpath);
                            if ($file) {
                                
                                // Reading each element's name in the sub directory
                                while (($filename = readdir($file)) !== false) {
                                    if ($filename != '.' && $filename != '..') {
                                        $image_path = '' . $dirpath . '' . $filename . '';

                                        // Creating array for each scanned file
                                        $key = array(
                                            'image_name' => trim($filename) ,
                                            'image_path' => str_replace('/SOME/PATH/', '', $image_path) ,
                                        );

                                        // Appending each image array
                                        $image_arrays[] = $key;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    return $image_arrays;
}

扫描PHP中的多个图像目录

一念一轮回 2025-02-09 15:25:44

如果您在循环内进行选择,则每行将是其自己的结果集。可能不是你想要的。

如果您需要即时生成它,我会选择作为一个查询而无需循环的查询,例如这样:

select current_date() + interval d10.n+d1.n day
from (
 select 0 as n union select 1 union select 2 union select 3 
 union select 4 union select 5 union select 6 union select 7 
 union select 8 union select 9
) as d1
cross join (
 select 0 as n union select 10 union select 20
) as d10;

这很尴尬。这就是为什么上面的评论建议创建一个每天用一行预先吞噬的“日历表”,然后您可以查询该表中的一系列行。即使您在接下来的100年中每天每天都有一排的填充,也只有36525行,对吗?仍然不是MySQL标准的大桌子。

或者,您可以升级到MySQL 8.0,您应该通过 2023年10月,因为那是时候MySQL 5.7达到生命的尽头。

If you do a SELECT inside the loop, each row will be its own result set. Probably not what you want.

If you need to generate it on the fly, I'd choose to do it as one query without a loop, for example something like this:

select current_date() + interval d10.n+d1.n day
from (
 select 0 as n union select 1 union select 2 union select 3 
 union select 4 union select 5 union select 6 union select 7 
 union select 8 union select 9
) as d1
cross join (
 select 0 as n union select 10 union select 20
) as d10;

This is admittedly pretty awkward. That's why the comment above suggested to create a "calendar table" that is prepopulated with one row per day, and then you can query that table for a range of rows. Even if you populate it with a row for every day for the next 100 years, that's only about 36525 rows, right? Still not a large table by MySQL standards.

Or you could upgrade to MySQL 8.0, which you should do by October 2023 anyway, because that's when MySQL 5.7 reaches its end of life.

循环时使用mySQL创建时间数据集

一念一轮回 2025-02-09 06:47:50

由于您没有提供最小的可重复示例。该代码作为练习留给您:

import tkinter as tk
import math
import random

RADIUS = 10
SEEDS = 10

def random_point(x,y):
    a = random_angle = 2*math.pi*random.random()
    r = random_radius= RADIUS*math.sqrt(random.random())
    random_x = r*math.cos(a)+x
    random_y = r*math.sin(a)+y
    return random_x,random_y

def paint(event):
    x = event.x
    y = event.y
    canvas = event.widget
    for i in range(SEEDS):
        random_x,random_y = random_point(x,y)
        canvas.create_line(random_x,random_y,random_x+1,random_y+1,fill='black')
    

root = tk.Tk()
cnvs = tk.Canvas(root)
cnvs.bind('<Motion>',paint)
cnvs.pack()
root.mainloop() 

愉快的编码!

Since you did not provide a minimal reproducible example. The code is left as an exercise to you:

import tkinter as tk
import math
import random

RADIUS = 10
SEEDS = 10

def random_point(x,y):
    a = random_angle = 2*math.pi*random.random()
    r = random_radius= RADIUS*math.sqrt(random.random())
    random_x = r*math.cos(a)+x
    random_y = r*math.sin(a)+y
    return random_x,random_y

def paint(event):
    x = event.x
    y = event.y
    canvas = event.widget
    for i in range(SEEDS):
        random_x,random_y = random_point(x,y)
        canvas.create_line(random_x,random_y,random_x+1,random_y+1,fill='black')
    

root = tk.Tk()
cnvs = tk.Canvas(root)
cnvs.bind('<Motion>',paint)
cnvs.pack()
root.mainloop() 

Happy coding!

铅笔在Tkinter帆布上绘制

一念一轮回 2025-02-09 02:45:52

带有SP的示例表:

CREATE TABLE STUDENT_GRADE
(
STD_ID INT
,FULL_GRADE VARCHAR(200)
)
INSERT INTO STUDENT_GRADE VALUES (1,'#1 OF 50 STUDENTS IN CLASS')
INSERT INTO STUDENT_GRADE VALUES (2,'#2 OF 50 STUDENTS IN CLASS')
INSERT INTO STUDENT_GRADE VALUES (3,'#3 OF 50 STUDENTS IN CLASS')
INSERT INTO STUDENT_GRADE VALUES (4,'#4 OF 50 STUDENTS IN CLASS')
INSERT INTO STUDENT_GRADE VALUES (5,'#5 OF 50 STUDENTS IN CLASS')

SELECT *FROM STUDENT_GRADE

CREATE PROCEDURE SP_STUDENT_GRADE
AS
BEGIN
    IF OBJECT_ID('tempdb..#TEMP') IS NOT NULL
    DROP TABLE #TEMP 

    CREATE TABLE #TEMP (FULL_GRADE VARCHAR(100), RANKING VARCHAR(20), TOTAL VARCHAR(20))
    DECLARE @STRING VARCHAR(100)
    DECLARE @RANKING VARCHAR(20)
    DECLARE @TOTAL VARCHAR(20)
    DECLARE @ID INT = 1
    DECLARE @FOR_LOOP INT
    SET @FOR_LOOP = (SELECT COUNT(*) FROM STUDENT_GRADE)
    WHILE @ID <= @FOR_LOOP
    BEGIN
        SET @STRING = (SELECT FULL_GRADE FROM STUDENT_GRADE WHERE STD_ID = @ID)
        SET @RANKING = (SELECT SUBSTRING(@STRING,2,CHARINDEX(' ',@STRING)-1))

        DECLARE @STRING_TOTAL VARCHAR(100)
        SET @STRING_TOTAL = (SELECT SUBSTRING(@STRING,CHARINDEX(' ',@STRING)+1,LEN(@STRING)))
        DECLARE @STRING_TOTAL2 VARCHAR(100)
        SET @STRING_TOTAL2 = (SELECT SUBSTRING(@STRING_TOTAL,CHARINDEX(' ',@STRING_TOTAL)+1,LEN(@STRING_TOTAL)))
        SET @TOTAL = (SELECT SUBSTRING(@STRING_TOTAL2,1,CHARINDEX(' ',@STRING_TOTAL2)-1))
        
        INSERT INTO #TEMP VALUES 
        (@STRING, @RANKING, @TOTAL)
        SET @ID = @ID +1
    END
    SELECT *FROM #TEMP
END

SP_STUDENT_GRADE

Sample table with SP:

CREATE TABLE STUDENT_GRADE
(
STD_ID INT
,FULL_GRADE VARCHAR(200)
)
INSERT INTO STUDENT_GRADE VALUES (1,'#1 OF 50 STUDENTS IN CLASS')
INSERT INTO STUDENT_GRADE VALUES (2,'#2 OF 50 STUDENTS IN CLASS')
INSERT INTO STUDENT_GRADE VALUES (3,'#3 OF 50 STUDENTS IN CLASS')
INSERT INTO STUDENT_GRADE VALUES (4,'#4 OF 50 STUDENTS IN CLASS')
INSERT INTO STUDENT_GRADE VALUES (5,'#5 OF 50 STUDENTS IN CLASS')

SELECT *FROM STUDENT_GRADE

CREATE PROCEDURE SP_STUDENT_GRADE
AS
BEGIN
    IF OBJECT_ID('tempdb..#TEMP') IS NOT NULL
    DROP TABLE #TEMP 

    CREATE TABLE #TEMP (FULL_GRADE VARCHAR(100), RANKING VARCHAR(20), TOTAL VARCHAR(20))
    DECLARE @STRING VARCHAR(100)
    DECLARE @RANKING VARCHAR(20)
    DECLARE @TOTAL VARCHAR(20)
    DECLARE @ID INT = 1
    DECLARE @FOR_LOOP INT
    SET @FOR_LOOP = (SELECT COUNT(*) FROM STUDENT_GRADE)
    WHILE @ID <= @FOR_LOOP
    BEGIN
        SET @STRING = (SELECT FULL_GRADE FROM STUDENT_GRADE WHERE STD_ID = @ID)
        SET @RANKING = (SELECT SUBSTRING(@STRING,2,CHARINDEX(' ',@STRING)-1))

        DECLARE @STRING_TOTAL VARCHAR(100)
        SET @STRING_TOTAL = (SELECT SUBSTRING(@STRING,CHARINDEX(' ',@STRING)+1,LEN(@STRING)))
        DECLARE @STRING_TOTAL2 VARCHAR(100)
        SET @STRING_TOTAL2 = (SELECT SUBSTRING(@STRING_TOTAL,CHARINDEX(' ',@STRING_TOTAL)+1,LEN(@STRING_TOTAL)))
        SET @TOTAL = (SELECT SUBSTRING(@STRING_TOTAL2,1,CHARINDEX(' ',@STRING_TOTAL2)-1))
        
        INSERT INTO #TEMP VALUES 
        (@STRING, @RANKING, @TOTAL)
        SET @ID = @ID +1
    END
    SELECT *FROM #TEMP
END

SP_STUDENT_GRADE

如何从这组字符串中提取此特定数字?

一念一轮回 2025-02-08 12:47:00

您可以使用PANDAS库访问Excel数据,应该首先制作数据框架,然后可以使用Model.object.get_or_create方法保存数据。
在此之前,您应该首先在模型中定义表格以保存数据。

you can access excel data with pandas library, you should first make dataframe and then you can save your data using model.objects.get_or_create method in view.
before that you should first define your table in model for save data .

如何将数据添加到我的Django DB中。使用Excel作为输入?

一念一轮回 2025-02-08 04:44:02

要使 grid.Arrange 与补丁一起使用,您必须先使用 PatchWork :: PatchWorkGrob 首先将其转换为grob。此外,无需 grid.arrange(repandgrob(...))。只需使用 grid.arnange

grid.arrange(patchworkGrob(myplt), left = y.grob, bottom = x.grob)

“”

To make grid.arrange work with a patch you have to convert it to a grob first using patchwork::patchworkGrob. Additionally there is no need for grid.arrange(arrangeGrob(...)). Just use grid.arrange:

grid.arrange(patchworkGrob(myplt), left = y.grob, bottom = x.grob)

使用ggplot和plot_layout与textgrob一起安排的图的全局x和y标签

一念一轮回 2025-02-08 04:05:44

问题似乎在 @Manual标签中,可能是框架中的错误。执行测试时,通过添加“而不是 @Manual”来修复它。

The problem seems to be in the @manual tag, probably a bug in the framework. It is fixed by adding 'and not @manual' when executing tests.

Serenity&#x2B; Maven FailSafe忽略测试并在其上添加@Manual标签

更多

推荐作者

櫻之舞

文章 0 评论 0

弥枳

文章 0 评论 0

m2429

文章 0 评论 0

野却迷人

文章 0 评论 0

我怀念的。

文章 0 评论 0

更多

友情链接

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