<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def getNumberOfTokens(networkDataFile):
 """ Returns the number of tokens for each sequence @param networkDataFile (str) Path to file in the FileRecordStream format @return (list) list of number of tokens """

    try:
      with open(networkDataFile) as f:
        reader = csv.reader(f)
        next(reader, None)
        next(reader, None)
        resetIdx = next(reader).index("R")

        count = 0
        numTokens = []
        for line in reader:
          if int(line[resetIdx]) == 1:
            if count != 0:
              numTokens.append(count)
            count = 1
          else:
            count += 1
        numTokens.append(count)
        return numTokens

    except IOError as e:
      print "Could not open the file {}.".format(networkDataFile)
      raise e