File tree Expand file tree Collapse file tree 2 files changed +20
-18
lines changed Expand file tree Collapse file tree 2 files changed +20
-18
lines changed Original file line number Diff line number Diff line change 5
5
----------
6
6
问题
7
7
----------
8
- You need to get the terminal size in order to properly format the output of your program.
8
+ 你需要知道当前终端的大小以便正确的格式化输出。
9
9
10
10
|
11
11
12
12
----------
13
13
解决方案
14
14
----------
15
- Use the os.get_terminal_size() function to do this:
16
-
17
- >>> import os
18
- >>> sz = os.get_terminal_size()
19
- >>> sz
20
- os.terminal_size(columns=80, lines=24)
21
- >>> sz.columns
22
- 80
23
- >>> sz.lines
24
- 24
25
- >>>
15
+ 使用 ``os.get_terminal_size() `` 函数来做到这一点。
16
+
17
+ 代码示例:
18
+
19
+ .. code-block :: python
20
+
21
+ >> > import os
22
+ >> > sz = os.get_terminal_size()
23
+ >> > sz
24
+ os.terminal_size(columns = 80 , lines = 24 )
25
+ >> > sz.columns
26
+ 80
27
+ >> > sz.lines
28
+ 24
29
+ >> >
26
30
27
31
|
28
32
29
33
----------
30
34
讨论
31
35
----------
32
- There are many other possible approaches for obtaining the terminal size, ranging from
33
- reading environment variables to executing low-level system calls involving ioctl()
34
- and TTYs. Frankly, why would you bother with that when this one simple call will
35
- suffice?
36
+ 有太多方式来得知终端大小了,从读取环境变量到执行底层的 ``ioctl() `` 函数等等。
37
+ 不过,为什么要去研究这些复杂的办法而不是仅仅调用一个简单的函数呢?
Original file line number Diff line number Diff line change 59
59
32
60
60
>>> print (cfg.get(' server' ,' signature' ))
61
61
62
- =================================
62
+ \ = ================================
63
63
Brought to you by the Python Cookbook
64
- =================================
64
+ \ = ================================
65
65
>>>
66
66
67
67
If desired, you can also modify the configuration and write it back to a file using the
You can’t perform that action at this time.
0 commit comments