80. Python's sys Module
1. Accessing Command-Line Arguments
import sys
if __name__ == "__main__":
print("Command-line arguments:")
for arg in sys.argv:
print(arg)2. Exiting a Program with sys.exit()
import sys
def main():
print("This is an example of sys.exit()")
sys.exit(0)
if __name__ == "__main__":
main()3. Redirecting Output Using sys.stdout
4. Checking the Python Version with sys.version
5. Working with sys.path for Importing Modules
6. Getting the Size of an Object with sys.getsizeof()
7. Handling Standard Error Output with sys.stderr
8. Getting the Recursion Limit with sys.getrecursionlimit()
9. Using sys.stdin for User Input
10. Exiting with an Error Code Using sys.exit()
Last updated