我根据我看到的答案提出了一个问题。它使用线程池来管理线程,但每个线程都会打印'Going to sleep... i',休眠一段i时间然后再打印'Slept..'。我的问题是为什么它会打印'Going to sleep...Going to sleep...Going to sleep...'?\n除非我明确添加到字符串的末尾,否则它不会将它们打印在换行符上。这是我的输出,没有\n. `
Going to sleep...Going to sleep...Going to sleep...
Slept ..0
Going to sleep...
Slept ..1
Going to sleep...
Slept ..2
Slept ..3
Slept ..4
done!!`
Run Code Online (Sandbox Code Playgroud)
这是我的带有换行符的输出
Going to sleep...
Going to sleep...
Going to sleep...
Slept ..0
Going to sleep...
Slept ..1
Going to sleep...
Slept ..2
Slept ..3
Slept ..4
done!!
Run Code Online (Sandbox Code Playgroud)
Going to sleep...第一个和第一个之间的空格Slept..对我来说也很奇怪。 …
我正在尝试使用AVA编写测试,但我似乎无法让它工作写.fn通过我的所有函数传递回调函数,并在完成所有操作后调用它.我的考试是
import test from 'ava';
import fn from './index.js';
test('NonLiteral && Literal', function (t) {
fn('test.txt', '', function (res) {
console.log(res);
t.is(res, '');
});
});
Run Code Online (Sandbox Code Playgroud)
res是
This is a test
How is it going
So far!!!
Run Code Online (Sandbox Code Playgroud)
但它说我的测试正在通过.我一直在关注这个测试.这是我一直在关注的片段
test('throwing a named function will report the to the console', function (t) {
execCli('fixture/throw-named-function.js', function (err, stdout, stderr) {
t.ok(err);
t.match(stderr, /\[Function: fooFn]/);
// TODO(jamestalmage)
// t.ok(/1 uncaught exception[^s]/.test(stdout));
t.end();
});
});
Run Code Online (Sandbox Code Playgroud)
有人可以向我解释我做错了什么吗?
我正在尝试使用迭代器在Python中构建一个"船长".
这个想法是给定以下内容:
' '.join([str(i) for i in skippy([1,'a','b','b',2,1,1,1,'c','d','b'])
Run Code Online (Sandbox Code Playgroud)
我们得到了
1 b b 2 1 d b
Run Code Online (Sandbox Code Playgroud)
作为输出.规则是每当我们达到整数x时,我们跳过iterable中的以下 x项.
到目前为止,我有:
def skippy(it):
p = 0
for x in it:
if type(x) == int:
for x in range(x):
p = next(it)
yield p
Run Code Online (Sandbox Code Playgroud)
这不能按预期工作,任何关于如何解决它的想法?
仍然是新的PHP,但我无法弄清楚我的表单我做错了什么.当我点击提交时,它不会重定向到我的PHP脚本.所有文件都在同一个文件夹中
reservations.html
<html>
<body>
<h1>Reservations</h1>
<form action="reservations.php" method="POST">
<input id="city" name='city' type="text" placeholder="Airport Code or City"><br>
<input id='submit' name='submit' type="button" value="Submit">
</form>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
reservations.php
<?php
$city = $_POST['city'];
if (isset($_POST['submit'])){
print "<h1>$city</h1>";
}
?>
Run Code Online (Sandbox Code Playgroud)
也许我误解了它是如何工作的但我认为它会将url更改为server_url/reservations.php并显示我在文本框中键入的内容.