关于指纹的问题:
假设我和我的朋友手头上有很多时间,而且我们的记忆力非常好。
我把我的公钥发给他。为了证明他电脑上的钥匙与我寄给他的钥匙是一样的,我继续打电话给他,用 ASCII 读出整个钥匙,当他对照电脑上的内容进行检查时。(我知道如果我要通过电话阅读,根本没有必要发送密钥,但这只是为了举例。)
我的问题是:
通过电话向另一个人大声朗读整个密钥,并让他将其与计算机上的内容进行核对是否等同于比较密钥的指纹?即,指纹是否只是确保消息未被截取和篡改的一种手段?
比方说,我有一个列表datalist,用len(datalist) = 4.假设我希望列表中的每个元素都以这种方式表示在字符串中:
s = "'{0}'::'{1}'::'{2}' '{3}'\n".format(datalist[0], datalist[1], datalist[2], datalist[3])
Run Code Online (Sandbox Code Playgroud)
我不喜欢打datalist[index]那么多次,觉得应该有更有效的方法.我试过了:
s = "'{0}'::'{1}'::'{2}' '{3}'\n".format(datalist[i] for i in range(4))
Run Code Online (Sandbox Code Playgroud)
但这不起作用:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
IndexError: tuple index out of range
Run Code Online (Sandbox Code Playgroud)
有没有人知道有效和简洁地实现这一目标的有效方法?
我一直在看文档中的这个代码示例:
import re
from django.core.exceptions import ValidationError
from django.db import models
from django.utils.translation import gettext_lazy as _
def parse_hand(hand_string):
"""Takes a string of cards and splits into a full hand."""
p1 = re.compile('.{26}')
p2 = re.compile('..')
args = [p2.findall(x) for x in p1.findall(hand_string)]
if len(args) != 4:
raise ValidationError(_("Invalid input for a Hand instance"))
return Hand(*args)
class HandField(models.Field):
# ...
def from_db_value(self, value, expression, connection):
if value is None:
return value
return parse_hand(value)
def to_python(self, value):
if isinstance(value, …Run Code Online (Sandbox Code Playgroud) 在此示例中,第一个print语句输出由返回的字符串ball.__str__(),而其他两个则不:
class Ball:
def __init__(self, parent, xpos = 50, ypos = 50, radius = 100, vx = 0, vy = 0, mass = 1):
"""
x,y are positions
vx and vy are velocities in cells/second
"""
self.x = xpos
self.y = ypos
self.r = radius
self.vx = vx
self.vy = vy
self.mass = mass
self.board = parent
def __str__(self):
return "Ball: x={0}, y={1}, r={2}, vx={3}, vy={4}".format(self.x,self.y,self.r,self.vx,self.vy)
class Board:
def __init__(self, width = 100, height = 100, sps = …Run Code Online (Sandbox Code Playgroud) 如果我将 tf 占位符定义为:
tf.placeholder("float", [None, 10])
Run Code Online (Sandbox Code Playgroud)
是None做什么的?这个的线性代数解释是什么?水平向量?
我知道函数 count 可用于计算给定序列中元素的数量,如下所示:
count(result/actors/actor)
Run Code Online (Sandbox Code Playgroud)
在这个 XML 中:
<result>
<actors>
<actor id="00000015">Anderson, Jeff</actor>
<actor id="00000030">Bishop, Kevin</actor>
<actor id="0000000f">Bonet, Lisa</actor>
<actor id="916503207">Parillaud, Anne</actor>
<actor id="916503208">Pitt, Brad</actor>
<actor id="916503209">Freeman, Morgan</actor>
<actor id="916503211">Domingo, Placido</actor>
<actor id="916503210">Sharif, Omar</actor>
<actor id="1337">Doqumenteriet2011</actor>
</actors>
</result>
Run Code Online (Sandbox Code Playgroud)
但是如果我想知道一个值在给定序列中出现了多少次呢?
例如,如果我想知道每个演员 (actorRef) 在以下 XML 中出现了多少部电影:
<videos>
<video id="id1235AA0">
<title>The Fugitive</title>
<actorRef>00000003</actorRef>
<actorRef>00000006</actorRef>
</video>
<video id="id1244100">
<title>Enemy of the State</title>
<actorRef>00000009</actorRef>
<actorRef>0000000c</actorRef>
<actorRef>0000000f</actorRef>
<actorRef>00000012</actorRef>
</video>
<video id="id124E230">
<title>Clerks</title>
<actorRef>00000015</actorRef>
<actorRef>00000018</actorRef>
<actorRef>0000001b</actorRef>
</video>
Run Code Online (Sandbox Code Playgroud)
我可以轻松生成所有出现演员的列表,甚至可以让他们在我制作的序列中出现的次数与在 XML 中出现的次数一样多:
result/videos//actorRef
Run Code Online (Sandbox Code Playgroud)
但我不能做任何类似于例如 COUNT() 和 GROUP BY 在 SQL …
使用文件 super5.py:
class A:
def m(self):
print("m of A called")
class B(A):
def m(self):
print("m of B called")
super().m()
class C(A):
def m(self):
print("m of C called")
super().m()
class D(B,C):
def m(self):
print("m of D called")
super().m()
Run Code Online (Sandbox Code Playgroud)
我们可以做到以下几点:
>>> from super5 import D
>>> x = D()
>>> x.m()
m of D called
m of B called
m of C called
m of A called
Run Code Online (Sandbox Code Playgroud)
对我来说,这没有意义,因为当我执行时x.m(),我希望会发生以下情况:
m的D被执行,因此"m of D called"被输出。super().m()执行第二行,它首先将我们带到 …我一直在思考为什么我们不能在 javascript 中做到这一点。
document.getElementsByClassName('class1').getElementsByClassName('class2')
Run Code Online (Sandbox Code Playgroud)
这是行不通的,因为第一次getElementsByClassName调用会给我们一个 HTMLCollection,它没有getElementsByClassName定义。为什么是这样?以这种方式使用这将是一个很好的函数,因为它可以让您基于具有多个不同类而不只是一个类的元素来获取元素。
有没有什么办法:
这个用方括号将数字括起来的语法有什么作用?
new Integer[0];
Run Code Online (Sandbox Code Playgroud)
我在我维护的代码库中找到了它,但找不到任何相关文档。它的使用方式如下:
Set<Form> forms = getForms();
List<Form> formsList = Arrays.asList(forms.toArray(new Form[0]))
Run Code Online (Sandbox Code Playgroud) web.php:
Route::post('caption/{id}/delete', 'DetailController@deleteCaption');
Run Code Online (Sandbox Code Playgroud)
DetailController.php:
public function deleteCaption(Request $request, $id) {
$caption = Caption::findOrFail($id);
$caption->delete(); //doesn't delete permanently
return response(204);
}
Run Code Online (Sandbox Code Playgroud)
admin.blade.php:
<p value='{{$caption->id}}'>{{$caption->content}}</p>
<form action="caption/{{$caption->id}}/delete" method="post">
<button type="submit">Delete caption</button>
</form>
<form action="caption/{{$caption->id}}/approve" method="post">
<button type="submit">Accept caption</button>
</form>
Run Code Online (Sandbox Code Playgroud)
我想这样做,以便在删除图像后,用户被重定向回位于 localhost:8000/admin 的管理页面。
我怎样才能做到这一点?文档对我来说无法理解。