小编Sup*_*rio的帖子

一个函数如何调用同一个类中的另一个函数?如何修复未解决的参考错误?

我想创建一个包含两个函数的类,其中一个函数调用另一个函数,例如:

class Parser:

    def foo(a):
        return a
 
    def bar(b):
        return foo(b * 2)
Run Code Online (Sandbox Code Playgroud)

这会出错:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 6, in bar
NameError: name 'foo' is not defined
Run Code Online (Sandbox Code Playgroud)

python python-3.x

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

Python正则表达式仅删除两个1个字母的单词之间的空格

我尝试编写一个行为如下的代码:

输入:“ab ccc”->“ab ccc”

输入:“aa bb”->“aa bb”

输入:“aa bb c d”->“aa bb cd”

我成功编写了一个正则表达式模板,该模板找到了“a b”案例,但我不确定如何仅删除空格。这是我的尝试:

import re
sentence = "a b cc"
print(sentence)
pattern = re.compile(r'[^\s]{1}\s[^\s]{1}')
sentence = re.sub(pattern, 'xx', sentence)
print(sentence)
Run Code Online (Sandbox Code Playgroud)

python regex

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

查找适合组合条件的所有行

我正在寻找使用python\excel\sql\google表格的最佳方法 - 我需要找到所有符合n值列表中k值的行.

例如,我有一个名为Animals的表:

| Name     | mammal | move   |  dive |
+----------+--------+--------+-------+
| Giraffe  |  1     |    1   |   0   |
| Frog     |  0     |    1   |   1   |
| Dolphin  |  1     |    1   |   1   |
| Snail    |  0     |    1   |   0   | 
| Bacteria |  0     |    0   |   0   | 
Run Code Online (Sandbox Code Playgroud)

我想编写一个函数foo,其行为如下:

foo(布尔值的元组,最小匹配)

foo((1,1,1),3) -> Dolphin
foo((1,1,1),2) -> Giraffe, Dolphin, Frog
foo((1,1,1),1) -> Giraffe, Dolphin, Frog, Snail
foo((1,1,0),2) -> Giraffe, Dolphin
foo((0,1,1),2) …
Run Code Online (Sandbox Code Playgroud)

python sql excel google-sheets pandas

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

为什么析构函数在“返回0”之后调用?

这段代码:

#include <iostream>

class Base { };

class Derived : public Base
{
public:
    ~Derived()
    {
        std::cout<< "Derived dtor" << std::endl;
    }
};

int main()
{
    Derived objD;
    objD.~Derived();
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

印刷品:

Derived dtor // destructor called
Derived dtor // printed by 'return 0'
Run Code Online (Sandbox Code Playgroud)

我不知道第二行从何而来。

与此主要:

int main()
{
    Derived objD;
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

它只打印一行。

c++ destructor

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

标签 统计

python ×3

c++ ×1

destructor ×1

excel ×1

google-sheets ×1

pandas ×1

python-3.x ×1

regex ×1

sql ×1