简体   繁体   English

os.system('cls') 使用 ctypes.cdll.LoadLibrary 时不清除屏幕

[英]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__.pytls目录中:

# ------------------------------------------------------------------------------- #

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.

相关问题 os.system('cls') 不清除 Pycharm 中的屏幕? - os.system('cls') doesn't clear the screen in Pycharm? 使用ctypes.cdll.LoadLibrary从Python加载库时,无效的ELF标头 - Invalid ELF header when loading library from Python using ctypes.cdll.LoadLibrary 为什么os.system('cls') 不清除最近的output? - Why doesn't os.system('cls') clear the recent output? 压缩目录中 dll 上的 ctypes.cdll.LoadLibrary - ctypes.cdll.LoadLibrary on a dll in a zipped directory ctypes.CDLL() 和 ctypes.cdll.LoadLibrary() 有什么区别? - What is the difference between ctypes.CDLL() and ctypes.cdll.LoadLibrary()? Python ctypes.cdll.LoadLibrary在2.6.5和2.7.1之间的工作方式有所不同 - Python ctypes.cdll.LoadLibrary works differently between 2.6.5 and 2.7.1 ctypes.cdll.LoadLibrary真的有用吗? - What does ctypes.cdll.LoadLibrary really do? 强制 ctypes.cdll.LoadLibrary() 从文件重新加载库 - forcing ctypes.cdll.LoadLibrary() to reload library from file ctypes.cdll.LoadLibrary(无)如何工作? - How does ctypes.cdll.LoadLibrary(None) work? 如何清除 output 屏幕或 python 中的终端? os.system("clear") 和 os.system("cls") 不起作用。 (在谷歌合作实验室) - how do i clear the output screen or terminal in python? os.system("clear") and os.system("cls") did not work. (In google collaboratory)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM