import sys from pygments.lexers import guess_lexer_for_filename try: lexer_name = guess_lexer_for_filename(sys.argv[1], "").aliases[0] except: lexer_name = "" print lexer_name