<> 语法错误
Syntax Error with <>
我正在尝试做这个作业:
这就是我所拥有的,我在 >
上遇到语法错误
粘贴代码:
# 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()
只需将“<>”替换为“!=”,因为“<>”在 python3 中已弃用,可用作“!=”。
我正在尝试做这个作业:
这就是我所拥有的,我在 >
上遇到语法错误粘贴代码:
# 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()
只需将“<>”替换为“!=”,因为“<>”在 python3 中已弃用,可用作“!=”。