Program with Python that can read from a file, need to output number of character after line1 and recurrence of a character
<p>It is the first time that I work with Python and I have little experience with programming in general. I have to build a program with Python that can read from a file, need to output number of character after line1 and number of recurrence of a characters. I'm struggling and don't know how to count single characters of a file. I have to find the recurrence of 'C' and 'G' in a file but I haven't got any clues.
This is what I have done:</p>

<pre><code>while True:
    try:    
        filename = raw_input('Enter file:')

        filename = open(filename, "r+")

        line1 = filename.readline()
        num_lines = 0
        num_words = 0
        num_chars = 0
        len_line1 = len  (line1)

        for line in filename:
            words = line.split()

            num_lines += 1
            num_words += len(words)
            num_chars += len(line)

    except:
        break

print "Output is : ", line1

print "Length : ", num_chars - len_line1

print filename.split().index('C')
</code></pre>
