Created
February 1, 2025 00:19
-
-
Save shrimo/37debc4bfd50196190b7409c13f57553 to your computer and use it in GitHub Desktop.
Shebang Line
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/python3 | |
| """ | |
| In computing, a shebang is the character sequence #!, | |
| consisting of the characters number sign (also known as sharp or | |
| hash) and exclamation mark (also known as bang), | |
| at the beginning of a script. | |
| """ | |
| def print_first_line(file_path: str): | |
| """Reads and prints the first line of the given Python script.""" | |
| try: | |
| with open(file_path, "r", encoding="utf-8") as file: | |
| first_line = file.readline().strip() | |
| print(f"shebang: {first_line}") | |
| except FileNotFoundError: | |
| print(f"Error: File '{file_path}' not found.") | |
| except Exception as e: | |
| print(f"Error: {e}") | |
| if __name__ == "__main__": | |
| print_first_line("shebang.py") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment