Skip to content

Instantly share code, notes, and snippets.

@shrimo
Created February 1, 2025 00:19
Show Gist options
  • Select an option

  • Save shrimo/37debc4bfd50196190b7409c13f57553 to your computer and use it in GitHub Desktop.

Select an option

Save shrimo/37debc4bfd50196190b7409c13f57553 to your computer and use it in GitHub Desktop.
Shebang Line
#!/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