我正在阅读这个问题的答案(关于"wat"视频),它说:
{}+[]
我目前正在从"权威指南"学习JS,所以我试着真正理解这样的事情.
我的问题是,JS何时决定将其解释{}
为空代码块,而不是空对象?
另外,我想了解Node.js和Firebug之间的一些不一致之处.
萤火虫:
Node.js的:
我试图模拟new Date()
返回一个特定的日期。以下代码:
const now = new Date()
jest.spyOn(global, 'Date').mockImplementation(() => now)
Run Code Online (Sandbox Code Playgroud)
给出一个编译错误:Argument of type '() => Date' is not assignable to parameter of type '() => string'. Type 'Date' is not assignable to type 'string'
。
我认为原因是 jest 认为我正在尝试模拟Date()
而不是new Date()
. 确实,Date()
返回一个字符串。我该如何解决这个问题?
什么sys.float_info.epsilon
回报?
在我的系统上,我得到:
>>> sys.float_info.epsilon
2.220446049250313e-16
>>> sys.float_info.epsilon / 2
1.1102230246251565e-16
>>> 0 < sys.float_info.epsilon / 2 < sys.float_info.epsilon
True
Run Code Online (Sandbox Code Playgroud)
这怎么可能?
编辑:
你没事,我以为epsilon会做min所做的事.所以我的意思是sys.float_info.min
.
EDIT2
每个人,尤其是约翰库格曼,谢谢你的回答!
有些人在玩我自己澄清事情:
>>> float.hex(sys.float_info.epsilon)
'0x1.0000000000000p-52'
>>> float.hex(sys.float_info.min)
'0x1.0000000000000p-1022'
>>> float.hex(1 + a)
'0x1.0000000000001p+0'
>>> float.fromhex('0x0.0000000000001p+0') == sys.float_info.epsilon
True
>>> float.hex(sys.float_info.epsilon * sys.float_info.min)
'0x0.0000000000001p-1022'
Run Code Online (Sandbox Code Playgroud)
因此epsilon * min
给出具有最小正有效数(或尾数)和最小指数的数字.
我super(type)
什么时候可以使用?不是super(type,obj)
,但super(type)
-用一个参数.
例如:
>>> import os
>>> '__dict__' in dir(os)
False
Run Code Online (Sandbox Code Playgroud)
但os.__dict__
显示有一个__dict__
属性.
我正在尝试使用python 2.7中的win32gui获取桌面上的项目数.
以下代码:win32gui.SendMessage(win32gui.GetDesktopWindow(), LVM_GETITEMCOUNT)
返回零,我不知道为什么.
我win32api.GetLastError()
后来写了,它也返回零.
提前致谢.
编辑:我需要使用这种方法,因为最终目标是获取图标的位置,并通过类似的方法完成.所以我只是想确保我知道如何使用这种方法.另外,我认为它可以提供与列出桌面内容不同的输出(可以吗?).第三,我如何获得这些职位的来源建议采用这种方式 - 例如http://www.codeproject.com/Articles/639486/Save-and-restore-icon-positions-on-desktop.
EDIT2:
获取计数的完整代码(对我不起作用):
import win32gui
from commctrl import LVM_GETITEMCOUNT
print win32gui.SendMessage(win32gui.GetDesktopWindow(), LVM_GETITEMCOUNT)
Run Code Online (Sandbox Code Playgroud)
再次感谢!
解:
import ctypes
from commctrl import LVM_GETITEMCOUNT
import pywintypes
import win32gui
GetShellWindow = ctypes.windll.user32.GetShellWindow
def get_desktop():
"""Get the window of the icons, the desktop window contains this window"""
shell_window = GetShellWindow()
shell_dll_defview = win32gui.FindWindowEx(shell_window, 0, "SHELLDLL_DefView", "")
if shell_dll_defview == 0:
sys_listview_container = []
try:
win32gui.EnumWindows(_callback, sys_listview_container)
except pywintypes.error as e:
if e.winerror …
Run Code Online (Sandbox Code Playgroud) 我想了解以下 TypeScript 行为:
下面的代码
let a: number
if (a === undefined) {
console.log("how?")
}
Run Code Online (Sandbox Code Playgroud)
抛出错误:“变量'a'在分配之前被使用。”。
但是下面的代码
let a: number
const f = (): void => {
if (a === undefined) {
console.log("how?")
}
}
f()
Run Code Online (Sandbox Code Playgroud)
工作正常并记录“如何?”。
这是为什么?而且,a === undefined
如果它的类型是 ,那又如何呢number
?
我正在学习CSS,我试图创建一个简单的布局.
我将"标题"设置为宽度为100%,将"左侧"设置为宽度为20%,将"右侧"设置为80%.但是标题的宽度大于左侧和右侧的总宽度.为什么这样以及如何解决?
div {
border-radius: 10px;
}
#header {
z-index: 1;
background-color: #80B7ED;
height: 50px;
width: 100%;
position: fixed;
}
.left {
background-color: #5A9DE0;
height: 400px;
width: 20%;
float: left;
position: relative;
}
.right {
background-color: #BFD9F2;
height: 400px;
width: 80%;
float: right;
position: relative;
}
#footer {
background-color: #80B7ED;
clear: both;
height:70px;
}
Run Code Online (Sandbox Code Playgroud)
<!DOCTYPE html>
<html>
<head>
<link type="text/css" rel="stylesheet" href="stylesheet.css"/>
<title></title>
</head>
<body>
<div id="header">
</div>
<div class="left">
</div>
<div class="right">
</div>
<div id="footer">
</div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
编辑 …
使用 python 2.7.6 64 位我输入:
>>> def f(a, b=5):
... pass
...
>>> f(b=3)
Run Code Online (Sandbox Code Playgroud)
然后我得到:
TypeError: f() takes at least 1 argument (1 given)
Run Code Online (Sandbox Code Playgroud)
当然我应该得到一些错误,因为我没有给参数赋值a
。但是我得到的错误消息并不意味着什么(1 至少是 1)。
这是一个错误,对吧?修好了吗?我找不到任何关于它的信息。
谢谢!
python ×5
python-2.7 ×3
css ×2
typescript ×2
dictionary ×1
dir ×1
direction ×1
epsilon ×1
firebug ×1
html ×1
javascript ×1
jestjs ×1
layout ×1
let ×1
mocking ×1
module ×1
node.js ×1
pywin32 ×1
spy ×1
stylesheet ×1
super ×1
supertype ×1
ui-select ×1
undefined ×1
unit-testing ×1
variables ×1
width ×1
win32gui ×1