小编Alb*_*ole的帖子

如何组织C++项目

我想知道在组织项目时C++的最佳实践是什么.我已经读过我应该将所有源文件(.cpp)放在src文件夹中,并且头文件(.h)应该放在include文件夹中.这是应该的方式,还是应该将我的头文件放在源文件夹中?

这是我的文件夹树结构

- Project
|
+--- src (.cpp)
|
+--- include (.h) ????
|
+--- test (cpp unit test)
|
+--- doc (docs)
Run Code Online (Sandbox Code Playgroud)

c++ directory tree project-structure

14
推荐指数
2
解决办法
5313
查看次数

减去数据框中的两列

我的df如下所示:

Index    Country    Val1  Val2 ... Val10
1        Australia  1     3    ... 5
2        Bambua     12    33   ... 56
3        Tambua     14    34   ... 58
Run Code Online (Sandbox Code Playgroud)

我想从每个国家的Val1中减去Val10,所以输出如下:

Country    Val10-Val1
Australia  4
Bambua     23
Tambua     24
Run Code Online (Sandbox Code Playgroud)

到目前为止,我已经:

def myDelta(row):
    data = row[['Val10', 'Val1']]
    return pd.Series({'Delta': np.subtract(data)})

def runDeltas():
    myDF = getDF() \
        .apply(myDelta, axis=1) \
        .sort_values(by=['Delta'], ascending=False)
    return myDF
Run Code Online (Sandbox Code Playgroud)

runDeltas导致此错误:

ValueError: ('invalid number of arguments', u'occurred at index 9')
Run Code Online (Sandbox Code Playgroud)

解决此问题的正确方法是什么?

python pandas

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

多阶段Dockerfile:FROM之前的ARG不被替换

我正在为darshan utils写一个多阶段的Dockerfile :

ARG DARSHAN_VER=3.1.6

FROM fedora:29 as build
RUN dnf install -y \
        gcc \
        make \
        bzip2 bzip2-devel zlib zlib-devel
RUN curl -O "ftp://ftp.mcs.anl.gov/pub/darshan/releases/darshan-${DARSHAN_VER}.tar.gz" \
    && tar ...


FROM fedora:29
COPY --from=build "/usr/local/darshan-${DARSHAN_VER}" "/usr/local/darshan-${DARSHAN_VER}"
...
Run Code Online (Sandbox Code Playgroud)

我建立它,docker build -t darshan-util:3.6.1 .我得到的错误是:

Step 5/10 : RUN curl -O "ftp://ftp.mcs.anl.gov/pub/darshan/releases/darshan-${DARSHAN_VER}.tar.gz"     && tar ...

 ---> Running in 9943cce1669c
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
...
curl: (78) RETR response: 550
The command …
Run Code Online (Sandbox Code Playgroud)

docker dockerfile docker-multi-stage-build

8
推荐指数
2
解决办法
942
查看次数

验证期间丢失字段 - 嵌套序列化器 create()

我不明白为什么特定字段会在 valid_data 中被删除。

当将输入发布到 create() 一个新实例时,以下行: thisLabel = ClassificationLabel.objects.get(identifier=label.identifier) 抛出错误,因为标识符属性不存在:

AttributeError at /api/v1/policies/ 
Run Code Online (Sandbox Code Playgroud)

'collections.OrderedDict' object has no attribute 'identifier

我在 Django REST 框架中有以下序列化器:

序列化器.py:

class ClassificationLabelDetailSerializer(serializers.ModelSerializer):

    class Meta:
        model = ClassificationLabel
        fields = ('displayName', 'helpText', 'identifier', 'backgroundColour', 'foregroundColour', 'comment', 'description', 'lastChanged', 'revision')
        read_only_fields = ('identifier', 'lastChanged', 'revision',)


class PolicySerializer(serializers.ModelSerializer):
    labels = ClassificationLabelDetailSerializer(many=True)

    class Meta:
        model = Policy
        fields = ('displayName', 'identifier', 'labels', 'lastChanged', 'description', 'comment')
        read_only_fields = ('identifier', 'lastChanged',)

    def create(self,validated_data):
        labelData = validated_data.pop('labels')
        thisPolicy = Policy.objects.create(**validated_data)
        for label in …
Run Code Online (Sandbox Code Playgroud)

django django-rest-framework

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