Write a program to accept a file name from the user and display all lines from the file which contain python comment character ‘#’


In [ ]:
def printFile():
    filename = raw_input('Enter file path: ')
    f = open(filename,'r')
    lines = f.read()
    for i in lines:
        if '#' in i:
            print i
    print 'Would you like to try with another file? Y/N'
    choice2 = raw_input()
    if choice2.lower() == 'y':
        printFile()
    else:
        print 'Thank You'
        exit()

def main():
    print 'Program to display all lines from a file which contains the character \'#\''
    print '1. Enter filename\n2.Quit'
    choice = int(raw_input())
    if choice == 1:
        printFile()
    elif chice == 2:
        exit()