Q:

Creating a list from a .txt using the for loop

I am trying to complete a worksheet, but got stuck again. I need to store all the comments of Mooneye Studios in a list that is updated each time there is a new comment from the creator of the project. I am trying to do so with the first two conditions in the for loop. I get moon = [\n, \n, \n....]. Any idea how to proceed and make this work?
The file looks like this http://imgur.com/bsSr06q.
comments = open('lostEmberComments.txt', 'r')
nbOfCom = 0 #counting the commentaries
people = []# list of ppl who have commented
creator = False # did the creator write the comment?
moon = [] # lists of comments made by the creator
temp= ''

for line in comments:
   # my attempt
   if '>>> Mooneye Studios' in line:
     creator = True
   if creator and '>>>' not in line:
     temp += line

   if '>>>' and 'Mooneye Studios' not in line:
     creator = False
       if temp != '':
         moon.append(temp)
         temp = ''

   # this section is for the first part of the excercise
   if '>>>' in line:
      nbOfCom += 1 # counting the commentaries
      if not line.rstrip('\n') in people:  # avoiding duplicates
        people.append(line.rstrip('\n'))

b = len(people)

print(moon)
print('Discussion participants: ', people)
print('There are ', b, 'contributors to the discussion.')
print('There are ',nbOfCom,' commentaries on this project.')

comments.close()

A:

The problem is not on the first two if statements but on the third if statement because the first part ('>>>') of the third if statement is always true.  It will then save only the first empty line of creator's comment by the second if statement.  The change mentioned by @juanpa, if '>>>' in line and 'Mooneye Studios' not in line, may solve the problem.
There is also another issue of your code that if the last comment in the file is from creator, it will not be saved to moon[].
Below is my suggested solution:
nbOfCom = 0
people = []
creator = False
moon = []
temp = ''

with open('lostEmberComments.txt') as comments:
    for line in comments:
        if line.startswith('>>> '): # start of new comment
            nbOfCom += 1
            if temp and creator: # previous comment is from creator
                moon.append(temp)
                temp = ''
            commenter = line.rstrip()[4:] # get the commenter's name
            creator = 'Mooneye Studios' == commenter
            if commenter not in people:
                people.append(commenter)
        elif creator:
            temp += line # save creator's comment

# don't miss the last comment in file if it is from creator
if temp and creator:
    moon.append(temp)

print(moon)
print('Discussion participants:', people)
print('There are', len(people), 'contributors to the discussion.')
print('There are', nbOfCom, 'commentaries on this project.')

