NIUCLOUD是一款SaaS管理后台框架多应用插件+云编译。上千名开发者、服务商正在积极拥抱开发者生态。欢迎开发者们免费入驻。一起助力发展! 广告
## 问题 You need to get the terminal size in order to properly format the output of your program. ## 解决方案 Use the os.get_terminal_size() function to do this: >>> import os >>> sz = os.get_terminal_size() >>> sz os.terminal_size(columns=80, lines=24) >>> sz.columns 80 >>> sz.lines 24 >>> ## 讨论 There are many other possible approaches for obtaining the terminal size, ranging fromreading environment variables to executing low-level system calls involving ioctl()and TTYs. Frankly, why would you bother with that when this one simple call willsuffice?