How can you get the current filename in Python?

You can use __file__ in Python to get the path and filename of the current file. To only get the filename, you can use the os.path.basename() method to extract the filename part.

The following is an example.

import os

file_name = os.path.basename(__file__)
print(file_name)

Output:

example.py
bannerAds