我在理解行为方面遇到了问题JSON.parse.JSON.parse应该只适用于字符串.但它似乎适用于只包含一个字符串(甚至是单引号)的数组,如果字符串只包含数字.
JSON.parse(['1234']) // => 1234
JSON.parse(['1234as']) // => throws error
JSON.parse(['123', '123']) // => throws error
Run Code Online (Sandbox Code Playgroud) 我在javascript中对async await相当新,所以这个问题可能是我不知道的.
我有这个
async foo(req, res, next) {
try {
await scan(req.params.stack);
res.send('ok');
} catch (err) {
res.status(500).send('fail');
}
}
async scan(stack) {
try {
const libs = [1,2,3];
const promises = libs.map(async l => analyze(stack, l)
.catch((err) => { throw new Error(err); }));
return q.allSettled(promises)
.then((results) => {
const rejected = results.filter(r => r.state === 'rejected');
if (rejected.length === results.length) throw new Error('Failed');
return results;
})
.catch((err) => {
throw new Error(err);
});
} catch (err) {
throw new …Run Code Online (Sandbox Code Playgroud) 我有一个目录结构如下的项目
.
??? Pipfile
??? Pipfile.lock
??? module
? ??? __init__.py
? ??? helpers
? ? ??? __init__.py
? ? ??? __pycache__
? ? ? ??? __init__.cpython-36.pyc
? ? ??? dynamo.py
? ? ??? logger.py
? ??? test.py
Run Code Online (Sandbox Code Playgroud)
相关代码
logger.py
import click
import sys
from tabulate import tabulate
def formatter(string, *rest):
return string.format(*rest)
def info(*rest):
"""Write text in blue color
"""
click.echo(click.style('? ' + formatter(*rest), fg='blue'))
Run Code Online (Sandbox Code Playgroud)
test.py
import helpers
helpers.logger.info('Trying')
Run Code Online (Sandbox Code Playgroud)
当我尝试使用命令运行
python3 module/test.py
Run Code Online (Sandbox Code Playgroud)
我得到这个错误
Traceback (most recent call last):
File …Run Code Online (Sandbox Code Playgroud) 我在控制台中搞了几件事.
!5 is actually false
0 is a falsy value, so
0 == !5 is true
Run Code Online (Sandbox Code Playgroud)
好的,但是当我尝试这个时
!0 is true
5 is a truthy, so
5 == !0 should be true
Run Code Online (Sandbox Code Playgroud)
但它没有,控制台说错了.为什么会这样?
javascript ×2
arrays ×1
async-await ×1
comparison ×1
conditional ×1
json ×1
module ×1
node.js ×1
pipenv ×1
python ×1
python-3.x ×1