打印列表时出现奇怪的字符

时间:2021-07-02 09:51:17

标签: python list special-characters

我有一个练习,我需要打印代表一列的给定字母的最高值。

代码有效,但列表的打印有一些我不知道如何摆脱的字符:

['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J']

如您所见,字母 A 前有一些字符。

#!/usr/bin/env python3

Book = open("Book1.csv","r")

MaxValue = 0
LettLocation = 0

print('Enter column letter:')
FindChar = input()

import csv
with open("Book1.csv", newline='') as f:
  Reader = csv.reader(f)
  FirstRow = next(Reader)
  print(FirstRow)
  for Incre in range(len(FirstRow)):
    if FirstRow[Incre] == FindChar:
        LettLocation = Incre
        break
    
  for row in Reader:
    FirstValue = int(row[LettLocation])
    if MaxValue < FirstValue:
        MaxValue = FirstValue

print("At column", FindChar, "The highest value is:", MaxValue)

1 个答案:

答案 0 :(得分:2)

那些是正在读入的文件中的字节顺序标记 (BOM)。 首先在参数中指定编码,如下所示:encoding='utf-8-sig'