Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/303.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 当我在另一个目录中打开一个文件时,它将赢得';不打印文件的内容,但打印目录?_Python_Path_Directory - Fatal编程技术网

Python 当我在另一个目录中打开一个文件时,它将赢得';不打印文件的内容,但打印目录?

Python 当我在另一个目录中打开一个文件时,它将赢得';不打印文件的内容,但打印目录?,python,path,directory,Python,Path,Directory,当我打开另一个目录中的文件(一个.txt文件)并打印它时,它只会在shell的末尾告诉我目录:mode='r'encoding='cp1252',而不是文件中写入的内容。它没有锁上,或者什么的 这是我的密码: import os direct = ('C:\\Users\\Joshua\\Documents') file =open(os.path.join(direct, "Test.txt"),'r') print(file) 文件目录正确且存在,因为我使用以下方法进行了检查: os.pa

当我打开另一个目录中的文件(一个.txt文件)并打印它时,它只会在shell的末尾告诉我目录:mode='r'encoding='cp1252',而不是文件中写入的内容。它没有锁上,或者什么的

这是我的密码:

import os
direct = ('C:\\Users\\Joshua\\Documents')
file =open(os.path.join(direct, "Test.txt"),'r')
print(file)
文件目录正确且存在,因为我使用以下方法进行了检查:

os.path.exists ('C:\\Users\\Joshua\\Documents')

在shell中。

您忘记使用正确的方法读取文件内容

file = open(os.path.join(direct, "Test.txt"),'r')
print(file.read())