[英]os.system('cls') Doesn't clear screen when using ctypes.cdll.LoadLibrary
I am facing issue when I import a Python file that uses ctypes.cdll.LoadLibrary
function. When I try that, os.system('cls')
doesn't clear the screen as it should.当我导入一个使用ctypes.cdll.LoadLibrary
function 的 Python 文件时,我遇到了问题。当我尝试这样做时, os.system('cls')
没有按预期清除屏幕。 When I remove the line with ctypes.cdll.LoadLibrary
, os.system('cls')
works properly.当我删除带有ctypes.cdll.LoadLibrary
的行时, os.system('cls')
正常工作。 The .DLL
file contains a GoLang TLS solution. .DLL
文件包含一个 GoLang TLS 解决方案。 Code snippets below.下面的代码片段。
Here's an example file where os.system('cls')
doesn't clear the screen.这是一个示例文件,其中os.system('cls')
不清除屏幕。
import os
import tls
session = tls.create_client()
print('Session created.')
os.system('cls')
print('Screen cleared.')
__init__.py
in tls
dir: __init__.py
在tls
目录中:
# ------------------------------------------------------------------------------- #
if getattr(sys, 'frozen', False):
file_dir = f'{sys._MEIPASS}/tls/titanium_tls'
else:
file_dir = os.path.dirname(os.path.abspath(__file__))
tls = ctypes.cdll.LoadLibrary(f'{file_dir}/titanum_test.{platform.system().lower()}' if str(platform.system()) != 'Windows' else f'{file_dir}/titanum_test.dll')
tls.Request.restype = ctypes.c_char_p
tls.Request.argtypes = [ctypes.c_char_p]
# ------------------------------------------------------------------------------- #
Output of example script:示例脚本的 Output:
Session created.
Screen cleared.
Process finished with exit code 0
Output when tls = ctypes.cdll.LoadLibrary(f'{file_dir}/titanum_test.{platform.system().lower()}' if str(platform.system()).= 'Windows' else f'{file_dir}/titanum_test.dll')
line is removed: Output 当tls = ctypes.cdll.LoadLibrary(f'{file_dir}/titanum_test.{platform.system().lower()}' if str(platform.system()).= 'Windows' else f'{file_dir}/titanum_test.dll')
行被删除:
Session created.
Screen cleared.
Process finished with exit code 0
The space is the place where os.system('cls')
is clearing the screen and it works properly when the line that I mentioned above is removed.空格是os.system('cls')
清除屏幕的地方,当我上面提到的行被删除时它可以正常工作。
Of course i cannot use my __init__.py
file when this line is removed.当然,删除此行后我无法使用我的__init__.py
文件。
Sorry if there are any issues inside my questions.抱歉,如果我的问题中有任何问题。
Output returned by print(os.system('cls'))
Is: 1
print(os.system('cls'))
返回的 Output 是: 1
I found solution.我找到了解决方案。 The soulution is:解决办法是:
import subprocess
subprocess.run('cls', shell=True)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.