小编Ton*_*Big的帖子

使用shared_ptr通过boost.python将base抽象为holder

我们小组正在使用C++开发一个数字框架.我们现在想要将我们框架的基本部分包装在Python中.我们选择的武器是Boost.Python,因为我们已经将Boost用于其他目的.我们只使用smart_ptrs来支持多态性.以下代码段是我们如何应用策略模式的简单示例:

#include <boost/shared_ptr.hpp>
struct AbsStrategy
{
  virtual std::string talk( ) = 0;
};

typedef boost::shared_ptr<AbsStrategy> StrategyPtr;

struct Foo : AbsStrategy
{
  std::string talk( )
  {
    return "I am a Foo!";
  }
};

struct Bar : AbsStrategy
{
  std::string talk( )
  {
    return "I am a Bar!";
  }
};

struct Client
{
  Client( StrategyPtr strategy ) :
          myStrategy( strategy )
  {
  }

  bool checkStrategy( StrategyPtr strategy )
  {
    return ( strategy == myStrategy );
  }

  StrategyPtr myStrategy;
};
Run Code Online (Sandbox Code Playgroud)

如果我像这样用Boost.Python包装整个东西

#include <boost/python.hpp> …
Run Code Online (Sandbox Code Playgroud)

c++ abstract-class shared-ptr boost-python

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

python boto3写入S3导致空文件

我在使用 Python 2.7 和 boto3 将文件写入 S3 存储桶时遇到问题。具体来说,当我写入 EC2 实例上的文件时,关闭它,然后尝试将新文件写入 S3 存储桶,我看到一个文件已写入,但它是空的(0 字节)。这是代码片段:

!/usr/bin/python

import boto3

newfile = open('localdestination','w')

newfile.write('ABCDEFG')

newfile.close

fnamebuck = 'bucketdestination'

client = boto3.client('s3')

inptstr = 'localdestination'

client.upload_file(inptstr, 'bucketname', fnamebuck)
Run Code Online (Sandbox Code Playgroud)

我曾尝试修改权限、在文件关​​闭后添加延迟、更改我的变量名称以及各种代码更改,但都无济于事。我没有收到任何错误消息。任何想法这个 S3 存储桶写入有什么问题?

python amazon-s3 amazon-web-services boto3

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