小编Sam*_*are的帖子

在Python中操作二进制数据

我打开一个像这样的二进制文件:

file = open("test/test.x", 'rb')
Run Code Online (Sandbox Code Playgroud)

并阅读列表中的行.每行看起来有点像:

'\xbe\x00\xc8d\xf8d\x08\xe4.\x07~\x03\x9e\x07\xbe\x03\xde\x07\xfe\n'
Run Code Online (Sandbox Code Playgroud)

我很难操纵这些数据.如果我尝试打印每一行,python冻结,并发出哔哔声(我认为那里有一个二进制哔声代码).如何安全地使用这些数据?如何将每个十六进制数转换为十进制?

python binary hex python-2.7

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

用Golang调用SOAP

我是golang的新手,并尝试用gowsdl拨打肥皂.

我生成了wsdl代码并将其作为包安装.但是我很难理解从中调用方法的语法.

当我检查包装时,这就是我想要的肥皂体:

type AccountUser struct {
    XMLName xml.Name `xml:"http://exacttarget.com/wsdl/partnerAPI AccountUser"`

    *APIObject

    AccountUserID             int32         `xml:"AccountUserID,omitempty"`
    UserID                    string        `xml:"UserID,omitempty"`
    Password                  string        `xml:"Password,omitempty"`
    Name                      string        `xml:"Name,omitempty"`
    Email                     string        `xml:"Email,omitempty"`
    MustChangePassword        bool          `xml:"MustChangePassword,omitempty"`
    ActiveFlag                bool          `xml:"ActiveFlag,omitempty"`
    ChallengePhrase           string        `xml:"ChallengePhrase,omitempty"`
    ChallengeAnswer           string        `xml:"ChallengeAnswer,omitempty"`
    UserPermissions           []*UserAccess `xml:"UserPermissions,omitempty"`
    Delete                    int32         `xml:"Delete,omitempty"`
    LastSuccessfulLogin       time.Time     `xml:"LastSuccessfulLogin,omitempty"`
    IsAPIUser                 bool          `xml:"IsAPIUser,omitempty"`
    NotificationEmailAddress  string        `xml:"NotificationEmailAddress,omitempty"`
    IsLocked                  bool          `xml:"IsLocked,omitempty"`
    Unlock                    bool          `xml:"Unlock,omitempty"`
    BusinessUnit              int32         `xml:"BusinessUnit,omitempty"`
    DefaultBusinessUnit       int32         `xml:"DefaultBusinessUnit,omitempty"`
    DefaultApplication        string        `xml:"DefaultApplication,omitempty"`
    Locale                    *Locale       `xml:"Locale,omitempty"`
    TimeZone                  *TimeZone     `xml:"TimeZone,omitempty"`
    DefaultBusinessUnitObject *BusinessUnit `xml:"DefaultBusinessUnitObject,omitempty"` …
Run Code Online (Sandbox Code Playgroud)

soap wsdl soap-client go

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

bash 脚本从 bash 脚本添加 git 凭据

我需要能够将 git 凭据从我的 bash 脚本添加到我的 bash 脚本,但无法弄清楚如何做到这一点。

git clone https://xxxxxxx
Run Code Online (Sandbox Code Playgroud)

会询问我的用户名和密码。

我如何在 bash 脚本中传递这些?

任何指针将不胜感激

linux bash shell scripting

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

无法在 alpine 镜像中使用 make

当我在 OSX 上运行它时,我无法make在 alpine 中工作 make update_tools,但是当我在 alpine 映像中运行它时,我收到以下错误:make:***没有规则来创建目标“update_tools”。停止。这是我的 Dockerfile 现在的样子:

#Download base image Alpine-3.9  Golang 1.12 
FROM golang:1.12-alpine3.9

# Set Working Directory is /usr/app
WORKDIR /usr/app

# Install Alpine Dependencies
RUN apk update && apk upgrade && apk add --update alpine-sdk && \
    apk add --no-cache bash git openssh make cmake 

COPY cosmos-sdk .

WORKDIR /usr/app/cosmos-sdk

RUN git checkout v0.33.0 && \
    make update_tools && \ 
    make vendor-deps && \ 
    make install && \
    gaiad init …
Run Code Online (Sandbox Code Playgroud)

makefile docker alpine-linux

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

内存中的 long long 类型表示

我想从 8 字节类型中提取字节,就像char func(long long number, size_t offset)偏移 n 那样,我将得到第nth 个字节 (0 <= n <= 7)。这样做时,我意识到我不知道 8 字节变量在内存中是如何实际表示的。我希望你能帮我弄清楚。我首先编写了一个简短的 python 脚本来打印A每个字节中由s(ascii 值为 65)组成的数字

sumx = 0
for x in range(8):
    sumx += (ord('A')*256**x)
    print('x {} sumx {}'.format(x,sumx))
Run Code Online (Sandbox Code Playgroud)

输出是

x 0 sumx 65
x 1 sumx 16705
x 2 sumx 4276545
x 3 sumx 1094795585
x 4 sumx 280267669825
x 5 sumx 71748523475265
x 6 sumx 18367622009667905
x 7 sumx 4702111234474983745
Run Code Online (Sandbox Code Playgroud)

在我看来,每个数字都是一串As 后跟 0。接下来我写了一个简短的 …

c++ long-integer

5
推荐指数
2
解决办法
392
查看次数

在macOS Sierra上安装Rust时无法写入.bash_profile

我正在尝试通过运行以下命令来安装Rust:

sudo curl https://sh.rustup.rs -sSf | sh
Run Code Online (Sandbox Code Playgroud)

我一直收到以下错误:

could not write rcfile file: '/Users/pro/.bash_profile'
info: caused by: Permission denied (os error 13
Run Code Online (Sandbox Code Playgroud)

macos terminal rust

4
推荐指数
2
解决办法
1571
查看次数

Hyperledger Fabric:对等链码实例化错误

启动容器时出错:无法生成特定于平台的 docker 构建:构建返回的错误:1“无法加载包:包 ../../bin/github.com/hyperledger/fabric/chaincode/marbles:open /bin /github.com/hyperledger/fabric/chaincode/marbles:没有这样的文件或目录。

我看到它正在寻找一个相对目录。相对于什么?链码安装很好。如果链码安装了,为什么找不到实例化?1个同行。1 个人订购者。频道加入很好。

hyperledger hyperledger-fabric

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

将 Azure CLI 命令的输出存储为变量

我需要存储 AZ cli 命令的输出,该命令将获取我的私有 IP 作为变量。

我在 bash 脚本中使用以下内容:

echo "Fetching Monitoring Server IP"
SERVER_IP=$(az vm show -n ${THIS_VM_NAME} -g ${RSC_GRP_NAME} --query privateIps -o tsv)
echo "$SERVER_IP
Run Code Online (Sandbox Code Playgroud)

看起来这不起作用,因为当我回显该变量时,它返回空。

+ THIS_VM_NAME=XXXX-XX-XX-XX-XX
+ echo 'Fetching Monitoring Server IP'
Fetching Monitoring Server IP
++ az vm show -n XXXX-XX-XX-XX-XX3 -g XXXX-XX-XX-XX-XX --query privateIps -o tsv
+ SERVER_IP=
+ echo ''
Run Code Online (Sandbox Code Playgroud)

我将不胜感激任何对此的指示

linux bash azure-cli

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

Scikit learn(Python 3.5):我是否需要导入库才能使其工作?

我正在使用Python Data Science Essentials(第2版).

该书提供以下代码:

chosen_random_state = 1
X_train, X_test, y_train, y_test = cross_validation.train_test_split(X, y, test_size=0.30, ran-dom_state=chosen_random_state)
print ("(X train shape %s, X test shape %s, \ny train shape %s, y test shape %s" \
% (X_train.shape, X_test.shape, y_train.shape, y_test.shape))
h1.fit(X_train,y_train)
print (h1.score(X_test,y_test)) 
Run Code Online (Sandbox Code Playgroud)

当我尝试运行它时,我收到以下错误:

-------------------------------------------------- ------------------------- NameError Traceback(最近一次调用last)in()1 chosen_random_state = 1 ----> 2 X_train,X_test, y_train,y_test = cross_validation.train_test_split(X,y,test_size = 0.30,random_state = chosen_random_state)3打印("(X列车形状%s,X测试形状%s,\n列车形状%s,y测试形状%s") %(X_train.shape,X_test.shape,y_train.shape,y_test.shape))4 h1.fit(X_train,y_train)5 print(h1.score(X_test,y_test))

NameError:未定义名称"cross_validation"

我怀疑我可能要导入一本书未提及的图书馆.我搜索了手册,但找不到这个功能.这是我需要创建的功能还是有人可以指向相关的库?

python python-3.x scikit-learn

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

无法在 Terraform ECS 提供程序中使用内存预留

我正在运行测试,我的容器不希望有硬内存限制,因为我以编程方式将虚拟机交换为更大尺寸的虚拟机,并且需要容器能够自动利用 CPU 和内存的增量。我想探索内存预留,因为它是软限制,并且如果虚拟机的内存不低,则允许容器扩展。不幸的是,这个参数似乎在任务定义中不起作用。有任何想法吗?

任务定义:

resource "aws_ecs_task_definition" "quorum" {
  family                   = "quorum-${var.consensus_mechanism}-${var.tx_privacy_engine}-${var.network_name}"
  container_definitions    = "${replace(element(compact(local.container_definitions), 0), "/\"(true|false|[0-9]+)\"/", "$1")}"
  requires_compatibilities = ["${var.ecs_mode}"]
  # cpu                      = "4096"
  # memory                   = "81920"
  memoryReservation        = "8192"
  network_mode             = "${var.ecs_network_mode}"
  task_role_arn            = "${aws_iam_role.ecs_task.arn}"
  execution_role_arn       = "${aws_iam_role.ecs_task.arn}"

  volume {
    name = "${local.shared_volume_name}"
  }

  volume {
    name      = "docker_socket"
    host_path = "/var/run/docker.sock"
  }

}

Run Code Online (Sandbox Code Playgroud)

错误:

[FINAL] Summary execution: 
Wrote summarry output to:  .mjolnir//output.log
2 errors occurred:
        * aws_ecs_service.quorum: 5 errors occurred:
        * aws_ecs_service.quorum[3]: Resource 'aws_ecs_task_definition.quorum' not found for …
Run Code Online (Sandbox Code Playgroud)

amazon-web-services amazon-ecs terraform

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

为什么我的阵列没有增长?

我正在尝试生成3 ||因子的数字 阵列中有5个.

这是我的代码的副本:

package main

import "fmt"

func main() {

    i := 0

    for i < 1000 {
        var nums []int

        if i%3 == 0 || i%5 == 0 {
            nums := append(nums, i)
            fmt.Println(nums)
        }

        i++

    }
}
Run Code Online (Sandbox Code Playgroud)

不幸的是,这并没有按计划通过在nums [0]上写入值来实现.这是我的终端输出的最后几个值.

[981]
[984]
[985]
[987]
[990]
[993]
[995]
[996]
[999]
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?

UPDATE

还试过这个:

var nums []int // initialize the slice outside for loop
for i < 1000 {
    if i%3 == 0 || i%5 == 0 {
        nums = …
Run Code Online (Sandbox Code Playgroud)

arrays for-loop go slice

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