line error on no. 7

Jean-Michel Pichavant jeanmichel at
Wed Jul 29 16:23:20 CEST 2015

----- Original Message ----- 
> From: "ltc hotspot" <ltc.hotspot at>
> To: "python-list at" <Python-list at>
> Sent: Tuesday, 28 July, 2015 10:21:59 PM
> Subject: line error on no. 7
> Hi Everyone,
> I'm writing python code to read a data text file, split the file into
> a list of words using the split(function) and to print the results
> in alphabetical order.
> The raw python code is located at
> The sample data is located at
> Desired Output: ['Arise', 'But', 'It', 'Juliet', 'Who', 'already',
> 'and', 'breaks', 'east', 'envious', 'fair', 'grief', 'is', 'kill',
> 'light', 'moon', 'pale', 'sick', 'soft', 'sun', 'the', 'through',
> 'what', 'window', 'with', 'yonder']
> There is a line error on no. 7
> What is the cause of this error?

> Regards,
> Hal

> Sent from Surface


It's better to post the code with your question.

Python 2.7

fname = raw_input("Enter file name: ")
fh = open(fname)
lst = list()
for line in fh:
    if fh == list: continue
print line.rstrip()

The main issue is that you've misspelled 'lst' in the for loop. You've used 'list' instead. 'list' is a built-in constructor for lists. You cannot split it. I'm also not sure what """ if fh == list:continue """ is supposed to achieve.

Try the following untested code:

words = []
for line in open(fname): # what if fname does not exist ?
print sorted(words)



The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.

More information about the Python-list mailing list