问题描述
我有以下代码来找到Linux中控制台的宽度,该控制台在Python 2.7和Python 3.X中都可以使用:
Severity Code Description Project File Line Suppression State
Error LNK2005 "class window_methods mw" (?mw@@3Vwindow_methods@@A) already defined in Main.obj SFML Project D:\Projects\Other\Libraries\SFML Template 5.0\SFML Project\SFML Project\Window.obj 1
Error LNK2005 "class sf::Event e" (?e@@3VEvent@sf@@A) already defined in Main.obj SFML Project D:\Projects\Other\Libraries\SFML Template 5.0\SFML Project\SFML Project\Window.obj 1
Error LNK2005 "class sf::RenderWindow w" (?w@@3VRenderWindow@sf@@A) already defined in Main.obj SFML Project D:\Projects\Other\Libraries\SFML Template 5.0\SFML Project\SFML Project\Window.obj 1
Error LNK1169 one or more multiply defined symbols found SFML Project D:\Projects\Other\Libraries\SFML Template 5.0\SFML Project\Debug\SFML Project.exe 1
在我的test_something.py文件中,我测试了一些调用 get_default_console_width()的函数,它给了我这个错误:
def get_default_console_width():
try:
from shutil import get_terminal_size
console_width,rows = shutil.get_terminal_size()
except Exception:
import termios,fcntl,struct,sys
s = struct.pack('hh',0)
x = fcntl.ioctl(sys.stdout.fileno(),termios.TIOCGWINSZ,s)
rows,console_width = struct.unpack("hh",x)
return console_width
我知道有些类似的帖子也有相同的问题,但是在这种情况下我没有找到任何有用的帮助。
感谢您的帮助!谢谢!
解决方法
大多数 IDE 像 PyCharm 或 Wing 都模拟了终端,因此运行包含 get_terminal_size()
的代码将触发 [Errno 25] Inappropriate ioctl for device
,因为操作系统无法在 IDE 中获取模拟终端的行和列。
在操作系统的本机终端中运行代码为我解决了这个问题。