Use os.path.splitext()
. The extension, if any, will be the second element in the returned tuple. It will contain the dot.
from os.path import splitext def main(): print splitext(__file__)[1] if __name__ == '__main__': main()
.py
Use os.path.splitext()
. The extension, if any, will be the second element in the returned tuple. It will contain the dot.
from os.path import splitext def main(): print splitext(__file__)[1] if __name__ == '__main__': main()
.py