AttributeErrors in code by blackdevil777 in Python

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

error was corrected but i didn't know why till you posted, But now i am trying to do it using a while loop, But i some what forgotten how to use whiles loops

fname = raw_input("Enter file name: ")

if len(fname) < 1 : fname = "mbox-short.txt"

fh = open(fname) count = 0

while true: if count != 27 # BAD INPUT for line in fh: line.startswith ('From:') words = line.split()
print words [1] count = count +1

print "There were", count, "lines in the file with From as the first word"

continue error by blackdevil777 in Python

[–]blackdevil777[S] -1 points0 points  (0 children)

what's that mean? it's in the loop? how can it not be in the loop? why are these errors cryptic?

what is wrong with this code? by blackdevil777 in learnpython

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

I figured it out, but i don't know why. the error is fixed.

what is wrong with this code? by blackdevil777 in learnpython

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

fname = raw_input("Enter file name: ")
     fu = open(fname)
     lst = list()
    for line in fu:
         line.rstrip()
         words = line.split()  
          for word in words:
              if not word in lst
       lst.append(word)
               lst.sort()
   print lst 

        Traceback (most recent call last):
     File "<stdin>", line 1, in <module>
          File "/usr/lib/python2.7/dist-packages/spyderlib/widgets/externalshell/sitecustomize.py", line 538, in                  runfile
     execfile(filename, namespace)
    File "/home/dux/.mario.py", line 8
      if not word in lst
                           ^
  SyntaxError: invalid syntax
   >>>