Syntax Error with <> [duplicate]

爷,独闯天下 提交于 2019-12-11 10:23:41

问题


I'm trying to do this assignment:

This is what I have and I am getting a syntax error on >

Pasted code:

# 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:


Just replace "<>" with "!=", since "<>" is deprecate in python3,which can be used as "!=".



来源:https://stackoverflow.com/questions/34521750/syntax-error-with

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!