Skip to content

Instantly share code, notes, and snippets.

@theikkila
Created January 17, 2013 22:18
Show Gist options
  • Save theikkila/4560348 to your computer and use it in GitHub Desktop.
Save theikkila/4560348 to your computer and use it in GitHub Desktop.
Calculates braces in file If eq prints OK, else FAIL
# Calculates braces in file
# If eq prints OK, else FAIL
import sys
fname = sys.argv[1]
file = open(fname, 'r')
OKGREEN = '\033[92m'
FAIL = '\033[91m'
ENDC = '\033[0m'
open = 0
close = 0
for char in file.read():
if char == '{':
open+=1
if char == '}':
close+=1
if open != close:
print (FAIL+"FAIL ("+fname+")"+ENDC)
else:
print(OKGREEN+"OK ("+fname+")"+ENDC)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment