...在读取文件中被错误地看到

时间:2019-03-08 23:18:05

标签: python file

我正在将python中的某个文件读入变量:

with open('Folder\\File.txt') as fileToRead:
    a=fileToRead.read()

但是,文件包含字符...(三个点)。无论出于何种原因,这些都将被读为…。为什么会发生这种情况,如何防止这种情况发生?读取文件时还需要注意其他符号吗?

2 个答案:

答案 0 :(得分:2)

尝试:

# if the file in the same directory 
file = "Filename.extension"
#else
file = "FullDestination/Filename.extension"
with open(file, 'r', encoding='utf-8') as f:
    content = f.readlines()
    print(content)

答案 1 :(得分:1)

fileToRead.read().decode('utf-8')