小编Mar*_*lla的帖子

string.replace的正确形式是什么?

遵循string.replace(http://docs.python.org/library/string.html)的Python文档:

string.replace(str,old,new [,maxreplace])

返回字符串str的副本,其中所有出现的substring old都替换为new.如果给出了可选参数maxreplace,则替换第一个maxreplace事件.

使用给定的格式会生成以下错误:

>>> a = 'grateful'
>>> a.replace(a,'t','c')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: an integer is required
Run Code Online (Sandbox Code Playgroud)

看起来很奇怪你需要重复"str",并且从错误中我猜到我的第三个参数被用于maxreplace.

格式:

string.replace(旧的,新的)

确实似乎按预期运作.

我想知道我是否误解了某些东西,而且Python文档中给出的形式实际上在某种程度上是正确的.

python string replace

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

python bcrypt 中“$2a$”的意义是什么?

通过 Google 和 SO 挖掘可以找到一些资源,但它们似乎是相互冲突且不完整的。

所以我的问题是:

python-bcrypt 中哈希值前面的 $2a$ 有什么意义?

我专门使用http://www.mindrot.org/projects/py-bcrypt/上的实现,但问题普遍适用。

此外,最好澄清一下它是否可以在 python-bcrypt 模块中配置?如果确实存在安全问题,需要您使用特定的、不同的实现。

python bcrypt

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

标签 统计

python ×2

bcrypt ×1

replace ×1

string ×1