在Python 3.10中读取CSV文件时看到的无效字符



我正在从CSV文件中读取一些url,并只是在控制台中打印它们。当我打印时,我看到一些url的'-'在控制台中被'–'取代。

我的函数读取csv如下:

def read_dict_csv():
list_of_urls = []
try:
with open('csv/result.csv', 'r') as csv_file:
csv_reader = csv.reader(csv_file)
#next(csv_reader)
for line in csv_reader:
#print(line[0])
list_of_urls.append(line[0])
except FileNotFoundError as exp:
print(exp.strerror, exp.filename)
return list_of_urls

我的CSV文件如下:

https://cab.rbi.org.in/[enter image description here][1]docs/Training Cards/Eight Things About Agriculture Commodity Futures You May Want to Know.pdf
https://cab.rbi.org.in/docs/Training Cards/Exposure Norms for UCBs – Important RBI Guidelines.pdf

这是编码的问题。对我有用的是传递open上的编码属性,所以你的代码将是:

with open('csv/result.csv', 'r', encoding='utf8') as csv_file:

相关内容

  • 没有找到相关文章

最新更新