Can you please explain why this happens in Python v3.8?
a=round(2.3)
b=round(2.4)
print(a,b)
print(type(a),type(b))
print(a is b)
print(id(a))
print(id(b))
Run Code Online (Sandbox Code Playgroud)
Output:
2 2
<class 'int'> <class 'int'>
False
2406701496848
2406701496656
>>>
Run Code Online (Sandbox Code Playgroud)
2 is within the range of the small integer caching. So why are there different objects with the same value?
我正在使用 Python 3.8.3 & 在检查字符串的 id 时,我得到了一些意外的输出,如下所示。
>>> a="d"
>>> id(a)
1984988052656
>>> a+="e"
>>> id(a)
1985027888368
>>> a+="h"
>>> id(a)
1985027888368
>>> a+="i"
>>> id(a)
1985027888368
>>>
Run Code Online (Sandbox Code Playgroud)
在将 "h" 添加到 a 的行之后,id(a) 没有改变。当字符串不可变时,这怎么可能?当我使用 a=a+"h" 而不是 a+="h" 并在 .py 文件中运行此代码时,我得到了相同的输出(我提到了这一点,因为在某些情况下我们可以在 shell 中运行时看到不同的输出并在保存到文件后运行相同的代码)
我正在尝试从服务器发送一个Set()
对象。但从客户端我得到一个空对象。socket.io
node.js
//server side
var set=new Set([1,2,3]);
socket.emit('set', set);
console.log(set); //Set(3) {1,2,3}
Run Code Online (Sandbox Code Playgroud)
//client side
socket.on('set',function(set){
console.log(set); //{}
});
Run Code Online (Sandbox Code Playgroud)
这是为什么 ?
我创建了一个向用户显示特定站点的应用程序,我正在使用 Web 视图来完成该任务。当我尝试加载该特定站点的 web 视图时,什么也没有显示,日志 cat 说,
E/chromium: [ERROR:ssl_client_socket_impl.cc(946)] 握手失败;返回 -1,SSL 错误代码 1,net_error -202
因此,经过一番搜索后,我发现这个答案可以忽略此 SSL 证书错误,并使用以下代码我可以加载该站点。
webView.setWebViewClient(new WebViewClient() {
@Override
public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
handler.proceed();
Log.d("ssl_error", error.toString());
}
});
Run Code Online (Sandbox Code Playgroud)
当我发送error.toString()
给 log cat 时,它说,
主要错误:3 证书:颁发给:[该特定站点的公司的一些详细信息] 颁发者:CN=GeoTrust RSA CA 2018,OU=www.digicert.com,O=DigiCert Inc,C=US;在 URL: [那个特定的站点 url]
但是我想在不忽略它的情况下修复该错误。
正如前面提到的堆栈溢出答案一样,我无法匹配https://developer.android.com/training/articles/security-config的详细信息来解决这个问题而不忽略它。我应该如何配置网络来解决这个问题?
注意:- 我只想在一个特定站点上工作。无需与任何网站合作
我正在创建简单的代码编辑器,它可以运行 python 代码并显示输出和错误消息。目前我可以运行 python 代码,但问题是输出显示在开发人员工具的控制台中。我想将输出和错误消息获取到 DOM 元素或作为字符串传递到 JS 脚本
<script type="text/python">
from browser import document, window
import tb as traceback
def run(event):
try:
exec(document['code'].value)
except Exception:
print(traceback.format_exc())
document['run'].bind('click',run)
</script>
Run Code Online (Sandbox Code Playgroud)
这是我的代码。'code' 是用于输入代码的文本框的 ID。'run' 是运行按钮的 id。我想将输出获取到另一个文本框或作为字符串获取到我的 js 脚本,而不是显示在开发人员工具的控制台中
python ×3
javascript ×2
android ×1
android-network-security-config ×1
brython ×1
editor ×1
html ×1
immutability ×1
integer ×1
java ×1
node.js ×1
python-3.8 ×1
python-3.x ×1
set ×1
socket.io ×1
ssl ×1
string ×1
webview ×1