我写了很多小脚本,逐行处理文件.在Perl中,我使用
while (<>) {
do stuff;
}
Run Code Online (Sandbox Code Playgroud)
这很方便,因为它不关心输入来自何处(文件或标准输入).
在Python中我使用它
if len(sys.argv) == 2: # there's a command line argument
sys.stdin = file(sys.argv[1])
for line in sys.stdin.readlines():
do stuff
Run Code Online (Sandbox Code Playgroud)
这似乎不是很优雅.是否有一个容易处理文件/标准输入的Python习语?
有没有办法修复某个窗口的高度,就像使用compilation-window-height的*compilation* buffers一样 ?