Ubuntu 18.04.2 LTS上的Python 3.7.1
使用Pycharm版本:
PyCharm 2019.1.3 (Professional Edition)
Build #PY-191.7479.30, built on May 30, 2019
Linux 4.18.0-22-generic我在调用os.get_terminal_size()函数时遇到了问题
从终端窗口运行该命令可以正常工作:
Python 3.7.1 (default, Oct 22 2018, 11:21:55)
[GCC 8.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.get_terminal_size()
os.terminal_size(columns=223, lines=18)但是从Python控制台窗口运行它不会
>>>import os
>>>os.get_terminal_size()
Traceback (most recent call last):
File "<input>", line 1, in <module>
OSError: [Errno 25] Inappropriate ioctl for device我的谷歌搜索并没有为我手头的问题提供太多具体的信息。OSError: [Errno 25] Inappropriate ioctl for device到底是什么意思,我该如何修复它?
发布于 2019-06-29 21:42:38
Python的实现依赖于终端是否符合操作系统对终端大小的请求。在CPython implementation中,ioctl()中的系统调用将失败,因为设备(终端)无法识别该命令。您可以尝试设置
-Drun.processes.with.pty=true根据this回答,在Help/Edit Custom VM Options...中。
发布于 2020-08-20 16:16:27
您可以使用shutil而不是os。这在Pycharm中工作没有任何问题(希望扩展到IntelliJ)。
import shutil
terminal_size = shutil.get_terminal_size(fallback=(120, 50))
# attributes
print('cols=', terminal_size.columns)
print('rows=', terminal_size.rows)https://stackoverflow.com/questions/56817448
复制相似问题