
####################################################################
# Opening a file:
#
# 'r' means read-only
#
#         file_for_reading = open('reading_file.txt', 'r')
#
# 'w' is write - will destroy the file if it already exists!
#
#         file_for_writing = open('writing_file.txt', 'w')
#
# 'a' is append - for adding to the end of the file
#
#         file_for_appending = open('appending_file.txt', 'a')
#
# don't forget to close your files when you're done
#
#         file_for_writing.close()

####################################################################
# Pythonic way to use files:
#
# you should always use them in a with block, 
# at the end of which they will be closed automatically:
#
#    with open(filename,'r') as f:
#        data = function_that_gets_data_from(f)


###############################################################
# Reading a file:
#
#     Use a for-loop to iterate over the lines in an opened file
#

import re

starts_with_hash = 0

with open('input.txt','r') as f:
    for line in f:		   # look at each line in the file
        if re.match("^#",line):	   # use a regex to see if it starts with '#'
            starts_with_hash += 1  # if it does, add 1 to the count

print("starts_with_hash = ", starts_with_hash)

