小编Sea*_*ais的帖子

Python单元测试和发现

我有目录,其中包含名为的文件: test_foo.py

每个文件都是一个测试用例.

我想要

1)从命令行运行目录中的所有测试.我正在使用unittest2,因为我们正在运行Python 2.5.1.从其中一个目录我尝试在命令行输入:

python -m unittest2 discover -p 'test_*.py'
Run Code Online (Sandbox Code Playgroud)

和几个不同的变种.我没有错,但没有任何反应.我期待该目录中所有测试用例中的所有测试都能运行并获得结果.

2)我也尝试在我执行此操作的目录中有一个脚本:

loader = unittest2.TestLoader()
t = loader.discover('.')
Run Code Online (Sandbox Code Playgroud)

如果我打印t变量,我可以看到我的测试用例,但是从文档中我无法弄清楚一旦我拥有它就如何处理加载器对象.

python unit-testing discovery

37
推荐指数
3
解决办法
3万
查看次数

如何从Python文件夹外部访问模块?

如何从其他文件夹访问模块?

这是文件结构:

/<appname>
    /config
        __init__.py
        config.py
    /test
        test.py # I'm here
Run Code Online (Sandbox Code Playgroud)

我想从test.py中访问config.py中的函数.我该怎么做?
这是我的导入:

import config.config
Run Code Online (Sandbox Code Playgroud)

当我运行test.py脚本时,它总会说:

ImportError: No module named config.config
Run Code Online (Sandbox Code Playgroud)

我做错什么了吗?

python

18
推荐指数
3
解决办法
2万
查看次数

如何使Pycharm更快/更轻?

我真的很喜欢Pycharm,并且很乐意使用它.然而,它消耗计算机处理能力和滞后的趋势是一个很大的缺点.

在不久的将来,我将运行一个介绍性的Python课程,并建议学生安装Pycharm,因为它似乎是最友好的IDE.

有没有办法加速Pycharm使其处理有点'更轻'?或者是否有其他具有类似功能的IDE,人们会推荐?

python ide pycharm

16
推荐指数
3
解决办法
2万
查看次数

如何在PHP中创建REST API?

我一直在开发游戏网站并计划添加API以允许开发人员为网站创建游戏.唯一的问题是如何使用PHP或任何其他可以开发API的语言更具体地创建API?

对不起,这是API开发的新功能.

任何帮助表示赞赏.

php api

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

C++中的fstream错误

我真的需要你的帮助.我似乎无法在C++中进行文件操作.我使用fstream进行一些文件操作,但是当我编译它时,会出现一个错误:

|63|error: no matching function for call to 'std::basic_fstream<char>::open(std::string&, const openmode&)'|
Run Code Online (Sandbox Code Playgroud)

我做错了什么?

以下是源代码的一部分:

#include<stdio.h>
#include<iostream>
#include<fstream>
#include<string>    

using namespace std;

inline int exports()
{
string fdir;
// Export Tiled Map
cout << "File to export (include the directory of the file): ";
cin >> fdir;
fstream fp; // File for the map
fp.open(fdir, ios::app);
if (!fp.is_open())
    cerr << "File not found. Check the file a file manager if it exists.";
else
{
    string creator, map_name, date;
    cout << "Creator's name: …
Run Code Online (Sandbox Code Playgroud)

c++ gcc fstream codeblocks syntax-error

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

如何在C中包含和使用cairo图形库?

我最近从项目网站下载并安装了C的Cairo图形库.

我尝试使用网站常见问题解答中的给定代码来运行开罗的hello world程序.在Terminal中,我应用了同一页面给出的相同命令来编译它.但是当我尝试编译它时,出现了未定义引用的错误.

在此输入图像描述

在终端中,输出是:

 cc -o hello $(pkg-config --cflags --libs cairo) hello.c
 /tmp/cco08jEN.o: In function `main':
 hello.c:(.text+0x1f): undefined reference to `cairo_image_surface_create'
 hello.c:(.text+0x2f): undefined reference to `cairo_create'
 hello.c:(.text+0x4e): undefined reference to `cairo_select_font_face'
 hello.c:(.text+0x6d): undefined reference to `cairo_set_font_size'
 hello.c:(.text+0x89): undefined reference to `cairo_set_source_rgb'
 hello.c:(.text+0xbb): undefined reference to `cairo_move_to'
 hello.c:(.text+0xcc): undefined reference to `cairo_show_text'
 hello.c:(.text+0xd8): undefined reference to `cairo_destroy'
 hello.c:(.text+0xe9): undefined reference to `cairo_surface_write_to_png'
 hello.c:(.text+0xf5): undefined reference to `cairo_surface_destroy'
 collect2: error: ld returned 1 exit status
Run Code Online (Sandbox Code Playgroud)

我的源代码是:

#include <cairo.h> …
Run Code Online (Sandbox Code Playgroud)

c cairo

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

为什么不能在带有格式说明符的 f 字符串表达式周围使用空格?

当我以类似的方式使用带有格式说明符的 f 字符串时

>>> x = 1
>>> f'{ x:02 }'
Run Code Online (Sandbox Code Playgroud)

它给了我ValueError: Unknown format code '\x20' for object of type 'int'。为了解决这个问题,我必须从 f 字符串表达式中删除周围的空格,例如f'{x:02}'.

为什么会这样呢?

python python-3.x f-string

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

在将派生类对象传递给C++中具有基类参数的函数时,为什么要传递引用而不是值?

如果我没记错的话,在Java中,我们可以将子类传递给具有超类的函数.代码看起来像这样.

// Assume the classes were already defined, and Apple
// and Pineapple are derived from Fruit.
Fruit apple = new Apple();
Fruit pineapple = new Pineapple();

public void iHaveAPenIHaveAn(Fruit fruit) { ... } // :)
...
public static void main(String[] arg)
{
    iHaveAPenIHaveAn(apple); // Uh! Apple-pen.
    iHaveAPenIHaveAn(pineapple); // Uh! Pineapple-pen.
}
Run Code Online (Sandbox Code Playgroud)

然而,在C++中,我注意到,从这里,你需要使用基类的引用变量(那是适当的期限?),而不是基类的常规变量.

假设你有两个类:一个基类A和一个A派生类B.

class A { ... };
class B : A { ... };
Run Code Online (Sandbox Code Playgroud)

如果我们有一个neverGonna()接受类A参数的函数,那么为什么函数看起来像这样:

void …
Run Code Online (Sandbox Code Playgroud)

c++

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

C#上不允许使用默认参数说明符错误

当我构建项目时,VC#表示不允许使用Default参数说明符.它引导我到这个代码:

public class TwitterResponse
{
    private readonly RestResponseBase _response;
    private readonly Exception _exception;

    internal TwitterResponse(RestResponseBase response, Exception exception = null)
    {
        _exception = exception;
        _response = response;
    }
Run Code Online (Sandbox Code Playgroud)

可能是我的错误?

c# .net-3.5 default-parameters

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

是否有必要在SQLAlchemy中使用`relationship()`?

我注意到许多SQLAlchemy教程会将relationship()多个表"连接"在一起,可能是一对一,一对多或多对多.但是,在使用原始SQL时,据我所知,您无法明确定义表之间的关系.

在什么情况下relationship()需要而不是必需的?为什么我们必须在SQLAlchemy中明确定义表之间的关系?

python sqlalchemy

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