如何强制pprint()每行打印一个list/tuple/dict元素?
>>> from pprint import pprint
>>> my_var = ['one', 'two', ('red','green'), {'state' : 'Oregon', 'city' : 'Portland'}]
>>> pprint(my_var)
['one', 'two', ('red', 'green'), {'city': 'Portland', 'state': 'Oregon'}]
Run Code Online (Sandbox Code Playgroud)
我希望输出类似于:
['one',
'two',
('red',
'green'),
{'city': 'Portland',
'state': 'Oregon'}]
Run Code Online (Sandbox Code Playgroud) 如何在bash交互式shell中轻松获取前一个命令的倒数第二个(倒数第二个)单词/参数?我经常在后台运行命令,我想获取之前指定的文件&,例如,
% echo foo > /tmp/foo &
% cat !$
% &
Run Code Online (Sandbox Code Playgroud)
在上面的例子中,!$给出最后一个单词,&.但我想要倒数第二个论点,/tmp/foo
请注意,可以使用类似范围的单词指示符!-1:3,但这对于具有大量单词的命令来说是不切实际的,其中不太明显有多少单词,例如,
% (set -x; date; pwd; git status; git diff; git log | tail -30; date; args=--verbose time make test; date) >& /tmp/log/make.test.20150122-Thu-0834 &
% echo !-1:30
/tmp/log/make.test.20150122-Thu-0834
Run Code Online (Sandbox Code Playgroud)
上面的示例有效,但您必须计算并知道您想要的单词是第30个单词,这非常耗时且容易出错.
有一个简单的方法来获得倒数第二个(倒数第二个)单词吗?
(请注意,此问题是指交互式shell中前一个命令的参数,而不是指从命令行传递给shell脚本的参数,因为这里的一些答案和注释是指.)
bash shell command-line command-line-arguments interactive-shell
我一直坚持让端口映射与我构建的 Docker 实例一起使用。curl localhost在 docker 容器中显示应用程序工作正常,但来自主机的curl 返回:
* Rebuilt URL to: 127.0.0.1/
* Hostname was NOT found in DNS cache
* Trying 127.0.0.1...
* Connected to 127.0.0.1 (127.0.0.1) port 80 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.35.0
> Host: 127.0.0.1
> Accept: */*
>
* Empty reply from server
* Connection #0 to host 127.0.0.1 left intact
curl: (52) Empty reply from server
Run Code Online (Sandbox Code Playgroud)
我已经用标志暴露了端口-p。我尝试过映射各种不同的端口。我该如何调试这个?端口映射有哪些常见问题?
如何从搜索返回的 splunk 事件列表中获取特定 splunk 事件的 url?
如果这是不可能的,并且我需要创建一个只返回该事件的搜索,那么我可以在查询中使用的每个事件是否有一些唯一的 ID?
我的应用程序是节点v4,我在v4上写回来并且从未需要更新它(如果它没有破坏...).也就是说,直到其中一个依赖项在次要版本更新中删除了v4支持.
我读到package-lock.json5.x + 中有这个想法
package-lock.jso当我必须从源重新安装时,n概念是否会阻止次要版本破坏我的应用程序的情况?
我基本上想验证一个node_modules是按预期工作,每次运行npm install我得到的都是node_modules我原来做的,即使依赖五深决定更新他们的包我不想要它.
我想静态创建一个 yup 模式(该模式定义一次),每次调用时都会采用一个动态变量(每次调用的变量可以不同)。这可能吗?
例如,
// file: schema.js
// create the schema once
yup = require('yup');
const schema = yup.mixed().test(
'my-test-name',
'cannot be an existing value',
value => !myArray.includes(value) // How to reference myArray here?
// As written, it results in "ReferenceError: myArray is not defined"
);
module.exports = schema;
// other file that imports the schema:
schema = require('./schema.js');
let myArray = ['blue', 'green'];
schema.validateSync('yellow'); // should pass validation, because 'yellow' not in myArray
myArray = ['orange', 'yellow'];
schema.validateSync('yellow'); // …Run Code Online (Sandbox Code Playgroud) Q1:我可以更改 Docker 在 macOS 上使用的 Linux 内核吗?
Q2:Docker什么时候升级Linux内核版本?
目前,截至:
2020 年 9 月 21 日,最新 Docker Desktop v2.3.0.5 (48029),引擎 19.03.12
它使用 Linux 内核 4.19.76(2018 年 10 月 22 日发布)。我预计它会使用更新的内核
(例如,Linux 5.8 于 2020 年 8 月 2 日发布;Linux 5.0 于 2019 年 3 月 3 日发布)。
$ docker run -it alpine uname -a
Linux f745312f5a3e 4.19.76-linuxkit #1 SMP Tue May 26 11:42:35 UTC 2020 x86_64 Linux
Run Code Online (Sandbox Code Playgroud)
相关:
Docker 如何在 macOS 主机下运行 Linux 内核?
我可以更改 Docker for Windows 中使用的内核吗?
https://kernelnewbies.org/LinuxVersions
我做了一个git rebase -i并重写了一次提交。
如何显示我提交的新提交消息和旧提交消息之间的差异?(例如,来自 中的提交git reflog)
我有一个看起来像这样的记录集(省略了无关的数据以保护容易无聊):
id | user_id | created | units
----+---------+-------------------------------+-------
1 | 1 | 2011-04-18 15:43:02.737063+00 | 20
2 | 1 | 2011-04-18 15:43:02.737063+00 | 4
3 | 1 | 2011-04-18 15:46:48.592999+00 | -1
4 | 1 | 2011-04-19 12:02:10.687587+00 | -1
5 | 1 | 2011-04-19 12:09:20.039543+00 | -1
6 | 1 | 2011-04-19 12:11:21.948494+00 | -1
7 | 1 | 2011-04-19 12:15:51.544394+00 | -1
8 | 1 | 2011-04-19 12:16:44.623655+00 | -1
Run Code Online (Sandbox Code Playgroud)
我希望得到一个看起来像这样的结果:
id | user_id | created | …Run Code Online (Sandbox Code Playgroud) 我最近使用 piprequests在 python 2.7 中安装包,但是为了这样做,我必须使用:
python -m pip install requests
Run Code Online (Sandbox Code Playgroud)
而不仅仅是:
python pip install requests
Run Code Online (Sandbox Code Playgroud)
这给了我一个错误:
无法打开文件 'pip: [Errno 2] 没有这样的文件或目录
为什么我需要添加-m?
docker ×2
node.js ×2
python ×2
annotate ×1
bash ×1
command-line ×1
dictionary ×1
django ×1
git ×1
git-commit ×1
git-diff ×1
git-rebase ×1
javascript ×1
linux ×1
linux-kernel ×1
list ×1
macos ×1
package.json ×1
pip ×1
port ×1
pprint ×1
pretty-print ×1
python-2.7 ×1
shell ×1
splunk ×1
splunk-query ×1
yup ×1