পাইথন স্ক্রিপ্টে প্রোগ্রামেটিক্যালি স্ক্রিন ক্লিয়ার করার জন্য `os.system()` ব্যবহার করা হয়। প্ল্যাটফর্ম অনুযায়ী কমান্ড ভিন্ন।
ক্রস-প্ল্যাটফর্ম ফাংশন
import os
from time import sleep
def screen_clear():
if os.name == 'posix': # Linux/macOS
_ = os.system('clear')
else: # Windows
_ = os.system('cls')
print("Platform:", os.name)
print("big output\n" * 5)
sleep(5)
screen_clear() # ৫ সেকেন্ড পর স্ক্রিন ক্লিয়ার হবে
আউটপুট
Platform: nt big output big output big output big output big output (৫ সেকেন্ড পর স্ক্রিন ক্লিয়ার হয়ে যাবে)
Jupyter Notebook-এ `IPython.display.clear_output()` ব্যবহার করা ভালো। `os.system` শেল কমান্ড এক্সিকিউট করে, তাই সিকিউরিটি রিস্ক থাকতে পারে অনট্রাস্টেড ইনপুটের साथে।