小编dar*_*sky的帖子

CURL命令行URL参数

我正在尝试DELETE使用CURL 发送带有url参数的请求.我在做:

curl -H application/x-www-form-urlencoded -X DELETE http://localhost:5000/locations` -d 'id=3'
Run Code Online (Sandbox Code Playgroud)

但是,服务器没有看到参数id = 3.我尝试使用一些GUI应用程序,当我将URL传递为:时http://localhost:5000/locations?id=3,它可以工作.我真的宁愿使用CURL而不是这个GUI应用程序.任何人都可以指出我做错了什么?

curl http

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

如何将Int转换为无符号字节和后退

我需要将一个数字转换为无符号字节.该数字始终小于或等于255,因此它将适合一个字节.

我还需要将该字节转换回该数字.我怎么用Java做到这一点?我尝试了几种方法而且都没有用.这就是我现在要做的事情:

int size = 5;
// Convert size int to binary
String sizeStr = Integer.toString(size);
byte binaryByte = Byte.valueOf(sizeStr);
Run Code Online (Sandbox Code Playgroud)

现在将该字节转换回数字:

Byte test = new Byte(binaryByte);
int msgSize = test.intValue();
Run Code Online (Sandbox Code Playgroud)

显然,这不起作用.出于某种原因,它总是将数字转换为65.有什么建议?

java int byte

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

port selfupdate:"macPorts来源:命令执行失败"

我正在尝试selfupdate我的Macports,但我收到以下消息:

Error: /opt/local/bin/port: port selfupdate failed: Error synchronizing 
MacPorts sources: command execution failed
Run Code Online (Sandbox Code Playgroud)

我检查了我/opt/local/bin/macports,目录不存在.相反,它在/opt/local/var.这可能是问题吗?

运行时-dt,我得到以下内容:

[Users/user] > selfupdate
DEBUG: MacPorts sources location: /opt/local/var/macports/sources/rsync.macports.org/release/base
--->  Updating MacPorts base sources using rsync
rsync: failed to connect to rsync.macports.org: Connection refused (61)
rsync error: error in socket IO (code 10) at /SourceCache/rsync/rsync-42/rsync/clientserver.c(105) [receiver=2.6.9]
Command failed: /usr/bin/rsync -rtzv --delete-after rsync://rsync.macports.org/release/base/ /opt/local/var/macports/sources/rsync.macports.org/release/base
Exit code: 10
DEBUG: Error synchronizing MacPorts sources: command execution failed
    while executing
"macports::selfupdate [array …
Run Code Online (Sandbox Code Playgroud)

macports

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

打印组合字符串和数字

要在Python中打印字符串和数字,除了执行以下操作之外还有其他方法:

first = 10
second = 20
print "First number is %(first)d and second number is %(second)d" % {"first": first, "second":second}
Run Code Online (Sandbox Code Playgroud)

python python-2.7

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

Flask - POST错误405方法不允许

我刚刚开始学习Flask,我正在尝试创建一个允许POST方法的表单.这是我的方法:

@app.route('/template', methods=['GET', 'POST'])
def template():
    if request.method == 'POST':
        return("Hello")
    return render_template('index.html')
Run Code Online (Sandbox Code Playgroud)

我的index.html:

<html>

<head>
  <title> Title </title>
</head>

<body>
  Enter Python to execute:
  <form action="/" method="post">
    <input type="text" name="expression" />
    <input type="submit" value="Execute" />
  </form>
</body>

</html>
Run Code Online (Sandbox Code Playgroud)

加载表单(在收到GET时呈现它)工作正常.但是,当我单击提交按钮时,我收到POST 405错误方法不允许.为什么不显示你好?

python post http flask

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

Python类成员

我只是在学习Python,而且我来自C背景,所以如果我在两者之间有任何困惑/混淆,请告诉我.

假设我有以下课程:

class Node(object):
    def __init__(self, element):
        self.element = element
        self.left = self.right = None

    @classmethod
    def tree(cls, element, left, right):
        node = cls(element)
        node.left = left
        node.right = right
        return node
Run Code Online (Sandbox Code Playgroud)

这是一个名为的类Node,它重载构造函数,以便能够在需要时处理不同的参数.

是什么定义之间的差异self.element__init__只(如上所示),而不是执行以下操作:

class Node(object):
    element, left, right = None
    def __init__(self, element):
        self.element = element
        self.left = self.right = None
Run Code Online (Sandbox Code Playgroud)

是不是self.element__init__相同类的element变量定义?这难道不只是简单地覆盖elementNoneelement传入值__init__

python class member-variables

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

Java,数组中的移位元素

我有一个Java对象数组,我试图将一个元素拉到顶部,然后将其余元素向下移动一个.

假设我有一个大小为10的数组,我试图拉第五个元素.第五个元素进入位置0,从0到5的所有元素将向下移动一个.

此算法未正确移动元素:

Object temp = pool[position];

for (int i = 0; i < position; i++) {                
    array[i+1] = array[i];
}
array[0] = temp;
Run Code Online (Sandbox Code Playgroud)

我该怎么做?

java arrays algorithm shift

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

Java中的静态最终变量

可能重复:
私有最终静态属性vs私有最终属性

声明变量之间有什么区别

static final int x = 5;
Run Code Online (Sandbox Code Playgroud)

要么

final int x = 5;
Run Code Online (Sandbox Code Playgroud)

如果我只希望变量是本地的,并且是常量(以后不能更改)?

谢谢

java static final

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

Python 3 Float十进制点/精度

我正在读一个带有浮点数的文本文件,所有文件都带有1或2个小数点.我正在使用float()将一行转换为浮点数,ValueError如果失败则引发一行.我将所有浮动存储在列表中.打印出来时,我想将其打印为2位小数浮点数.

假设我有一个带有数字-3,65,9,17,1的文本文件.我读了每一个,然后我将它们转换为float并将它们附加到列表中.现在在Python 2中,调用float(-3.65)返回-3.65.然而,在Python 3中,float(-3.65) returns-3.6499999999999999`失去了它的精度.

我想打印浮点列表,[-3.6499999999999999, 9.1699999999999999, 1.0]只有2个小数点.沿着行做某事'%.1f' % round(n, 1)会返回一个字符串.如何返回浮点数的所有两个小数点的列表,而不是字符串?到目前为止,我使用它来舍入它,[round(num, 2) for num in list]但需要设置小数点/精度而不是round().

python floating-point python-3.x

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

UICollectionView cellForItemAtIndexPath未注册单元格

我正在尝试使用UICollectionViewCell,因为我想要显示的只是一个图像.我可以将图像添加到使用细胞UIColor colorWithImage:UICollectionViewCellcontentView财产.

在我的loadView方法中,我正在注册单元格如下: [self.collectionView registerClass:[ImageCell class] forCellWithReuseIdentifier:@"MyCell"];

以下是我的cellForItemAtIndexPath方法:

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"MyCell" forIndexPath:indexPath];
    // cell customization
    return cell;
}
Run Code Online (Sandbox Code Playgroud)

当我运行它时,一旦它到达出列行,它就会崩溃并出现以下错误:

*** Assertion failure in -[UICollectionView _dequeueReusableViewOfKind:withIdentifier:forIndexPath:]

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'could not dequeue a view of kind: UICollectionElementKindCell with identifier MyCell - must register a nib or a class for the identifier or connect a prototype …
Run Code Online (Sandbox Code Playgroud)

xcode objective-c ipad ios uicollectionview

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