Sys Module
# Sys Module
# Provides functions and variables related to the Python runtime environment
# Gives access to data sent as part of the command line arguments when execurint scripts
# Import module
import sys
# Print Python version
print(sys.version)
# See current binary
print(sys.executable)
# See OS
print(sys.platform)
# Access low level functions
# Force python to flush buffer - will write everything directly to the terminal
for i in range(1,5):
sys.stdout.write(str(i))
sys.stdout.flush()
# Make a status bar to show progress of job
import time
for i in range(0,51):
time.sleep(0.1)
sys.stdout.write("{} [{}{}]\r".format(i, '#'*i, "."*(50-i)))
sys.stdout.flush()
sys.stdout.write("\n")
# Give a list of command line arguments given to script
print(sys.argv)
# Give error if arguments are missing
if len(sys.argv) != 3:
print("[X] To run {} enter a username and password".format(sys.argv[0]))
# Assign values
username = sys.argv[1]
password = sys.argv[2]
Last updated