小编Dri*_*ise的帖子

作业.C++ Book Example似乎有问题

以下代码是我的C++类幻灯片的一部分.IntelliSence给了我错误,我不知道为什么.不知道为什么它不喜欢构造函数和析构函数.有人可以帮忙吗?

class Vehicle {
     friend void guest();
 private:
     string make;
     string model;
     int year;
 public:
     void Vehicle();
     void Vehicle(string, string, int);
     void ~Vehicle();
     string getMake();
 }

 void guest() {
     cout << make;
 }

 1) IntelliSense: member function with the same name as its class must be a constructor
 2) IntelliSense: member function with the same name as its class must be a constructor
 3) IntelliSense: return type may not be specified on a destructor
Run Code Online (Sandbox Code Playgroud)

c++

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

Int 太大而无法在执行 .astype(int) 时转换为 C long

我运行一个python脚本,在那里我有一个字符串列从熊猫转换dfint使用astype(int)方法。但是,我收到以下错误:

"Python int too large to convert to C long"
Run Code Online (Sandbox Code Playgroud)

我的字符串都是字符串格式的数字,最多15个字符。有没有办法将此列转换为 int 类型而不会弹出此错误?

python numpy pandas

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

C++*vs []作为函数参数

有什么区别:

void foo(item* list)
{
    cout << list[xxx].string;
}
Run Code Online (Sandbox Code Playgroud)

void this(item list[])
{
    cout << list[xxx].string;
}
Run Code Online (Sandbox Code Playgroud)

假设项目是:

struct item
{
    char* string;
}
Run Code Online (Sandbox Code Playgroud)

指针指向字符数组的第一个

并且list只是一系列项目......

c++ arrays parameters struct pointers

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

在OpenCV C++中将图像区域设置为零的最佳方法?

我想问一下哪种方法是将灰度Mat图像的区域设置为零(或任何其他常量值)的最有效方法.

我应该创建一个零图像,然后使用copyTo()或有更好的方法吗?

c++ opencv

6
推荐指数
2
解决办法
9755
查看次数

PermissionError:[WinError 32]进程无法访问该文件,因为它正由另一个进程使用:

我正在尝试测试我自己的反网络版本,可以在这里找到.但是,我正在使用Pythons unittest模块进行测试.这是代码:

import unittest
from unittest.mock import patch
from antiweb import main
import sys
import os
import tempfile
import shutil

class Test_Antiweb(unittest.TestCase):


def setUp(self):

    self.test_dir = tempfile.mkdtemp()
    self.testfile_source ="#@start()\n\n#@include(test_area)\n\n#@start(test_area)\n#This is test_area text\n#@(test_area)"
    with open(os.path.join(self.test_dir, "testfile.py"), "w") as test:
        test.write(self.testfile_source)

def test_antiweb(self):
    self.test_args = ['antiweb.py', '-i', "-o docs", os.path.join(self.test_dir, "testfile.py")]
    with patch.object(sys, 'argv', self.test_args):
        success = main()
    self.assertTrue(success)

def tearDown(self):

    shutil.rmtree(self.test_dir)



if __name__ == '__main__':
    unittest.main()
Run Code Online (Sandbox Code Playgroud)

一切正常,除了tearDown功能.在没有执行unittest时tearDown,temp文件夹和他的内容被完美地创建.但是使用该tearDown函数我得到一个错误:

======================================================================
ERROR: test_antiweb (antiweb_tests.Test_Antiweb)
----------------------------------------------------------------------
Traceback …
Run Code Online (Sandbox Code Playgroud)

python shutil python-unittest

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

查找超过1小时但少于3天的文件

在linux中,使用bash,查找超过一小时但不到3天前修改过的文件的最简单方法是什么?

当然,必须有一个简单的方法来做到这一点.我一直在寻找,找不到一个简单的解决方案.

linux bash

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

连接到 Oracle RDS

我正在尝试使用 AWS lambda 和 python 连接到 Oracle。

这些是我遵循的步骤。(EC2实例一切都做完了)

  1. 下载了 Instantclient-basic-linux.x64-12.2.0.1.0.zip 和
    instantclient-sdk-linux.x64-12.2.0.1.0.zip
  2. 创建此文件夹结构 ~/lambda/lib/
  3. 解压zip文件中的~/lambda/lib/
  4. libaio.so.1.0.1from复制/lib64/~/lambda/lib/
  5. 创建了libaio.so.1.0.1as libaio.soin 的符号链接~/lambda
  6. 使用 pip 安装cx_Oracle~/lambda
  7. 写在index.py脚本下面~lambda

`

import cx_Oracle

def handler(event, context):
    message = ""
    cursor = None
    connection = None    
    try:
        connection = cx_Oracle.connect("USERNAME", "PASSWORD", "DOMAIN/orcl")
        cursor = connection.cursor()
        cursor.execute("""QUERY""")
    except Exception as e:
        message += " {Error in connection} " + str(e)
    finally: …
Run Code Online (Sandbox Code Playgroud)

python cx-oracle amazon-web-services amazon-rds aws-lambda

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

C++ lambdas作为类方法

作为一个假设的问题,我想使用lambdas作为类方法.我知道这在专业背景下很糟糕,但无论如何我很好奇.一个例子可能最适合展示我想做的事情.这是复数的基本类:

class Complex {
    private:
        double re, im;
    public:
        Complex() : re(0.0), im(0.0) {}
        Complex(double re, double im) : re(re * 1.0), im(im * 1.0) {}
        Complex(const Complex &c) = default;

        ~Complex() = default;

        function<double(void)> getRe = [=]() -> double { return re; };
        function<void(double)> setRe = [&](double re) -> void { this->re = re; };

        function<double(void)> getIm = [=]() -> double { return im; };
        function<void(double)> setIm = [&](double im) -> void { this->im = im; };

};
Run Code Online (Sandbox Code Playgroud)

起初我尝试使用 …

c++ methods performance lambda class

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

链接测试并将对象从一个测试传递到另一个

我正在尝试将一个测试的结果传递给pytest中的另一个测试-或更具体地说,重用第二个测试中由第一个测试创建的对象。这就是我目前的做法。

@pytest.fixture(scope="module")
def result_holder:
    return []

def test_creation(result_holder):
    object = create_object()
    assert object.status == 'created' # test that creation works as expected
    result_holder.append(object.id) # I need this value for the next test

# ideally this test should only run if the previous test was successful
def test_deletion(result_holder):
    previous_id = result_holder.pop()
    object = get_object(previous_id) # here I retrieve the object created in the first test
    object.delete()
    assert object.status == 'deleted' # test for deletion
Run Code Online (Sandbox Code Playgroud)

(在进一步介绍之前,我知道py.test将一项测试的结果传递给另一项 -但该问题的单个答案是题外话,问题本身已有 2年历史了)

像这样使用fixtures感觉不是很干净……而且如果第一个测试失败,行为也不清楚(尽管可以通过测试fixture的内容或在pytest doc中使用增量fixture来纠正)以及下面的评论)。是否有更好/更规范的方法来做到这一点?

python pytest

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

带有生成器的Python闭包

def multipliers():
  return [lambda x : i * x for i in range(4)]

print [m(2) for m in multipliers()]
Run Code Online (Sandbox Code Playgroud)

我部分理解(很危险)i所有功能都相同的原因,因为Python的闭包是后期绑定。

输出是[6, 6, 6, 6](不像[0, 2, 4, 6]我期望的那样)。


我看到它可以与生成器一起正常工作,我的预期输出来自以下版本。

def multipliers():
  return (lambda x : i * x for i in range(4))

print [m(2) for m in multipliers()]
Run Code Online (Sandbox Code Playgroud)

任何简单的解释为什么它可以在以下版本中使用?

python python-3.x

6
推荐指数
2
解决办法
242
查看次数