I would suggest something along these lines:
import re
def countNucleotides(filePath):
aCount = []
gCount = []
cCount = []
tCount = []
with open(filePath, 'rb') as data:
for line in data:
if not re.match(r'[agctAGCT]+',line):
break
aCount.append(notCount(line,'a'))
gCount.append(notCount(line,'g'))
cCount.append(notCount(line,'c'))
tCount.append(notCount(line,'t'))
def notCount(line, character):
appearances = 0
for item in line:
if item == character:
appearances += 1
return appearances
You can print them however you'd like after that.