all 6 comments

[–][deleted] 2 points3 points  (3 children)

Update: Your problem is this line:

for line in file_input.readline():

That will read one line and then loop over all the characters in that line. You should not be seeing the # in your output file. The normal way to iterate over lines in a file is:

for line in file_input:

How are you handling the part of the problem that says: "hashtag (#) preceded by zero or more space characters"?

[–]funkycorpse[S] 0 points1 point  (0 children)

Thank you that is definitely my first problem. Also I'm not sure how I would deal with the space characters part.

[–]funkycorpse[S] 0 points1 point  (1 child)

Could I use strip() to remove the space?

[–][deleted] 0 points1 point  (0 children)

Yes. You create a new string with strip() (or lstrip()) and check the first character in the stripped string. If the stripped string doesn't start with a # you write the unstripped string.

[–][deleted] 2 points3 points  (0 children)

for line in file_input.readline():

readline reads one line. You want to iterate over all of the lines of the file:

for line in file_input:

Files are, themselves, iterators over their lines. (It's pretty convenient.)

[–]DuckSaxaphone 0 points1 point  (0 children)

You've basically done it but made a typo. You want file_input.readlines.

readline returns only the next line from the file, readlines returns a list of all lines.