<>语法错误

时间:2015-12-30 01:38:38

标签: python syntax-error

我正在尝试执行此任务:

这就是我所拥有的,我在>

上遇到语法错误

粘贴代码:

# Specify where the input and output file is

InputFile = open('C:\Python\unsorted_fruits.txt', 'r')
OutputFile = open('C:\Python\sorted_fruits.txt', 'w')

# Read the input file

Fruits = InputFile.readlines()

# Sort the items in the list
Fruits.sort()

# Remove the blank lines and write the file
for fruit in Fruits:
    if fruit <>"\n":    # if fruit is blank, skip the write
        OutputFile.write(fruit) # otherwise write the fruit to the output file


# Close the input and output file
InputFile.close()
OutputFile.close()

1 个答案:

答案 0 :(得分:0)

只需替换“&lt;&gt;”用“!=”,因为“&lt;&gt;”在python3中弃用,可以用作“!=”。