vs code 中的 Jupyter Notebook:python 命令不显示/从内存中读取文件
Jupiter Notebook in vs code: python command not showing/ reading file from memory
我的代码在 运行 从存储位置读取文件的特定命令后没有显示任何输出。我还是个初学者,所以我有点困惑。将我的代码放在下面
您没有读取您的代码文件,因此它不显示任何输出。
试试这个
path = <path of you file>
file = open(path, mode="r")
file.read()
file.close()
您还可以进一步简化它
with open(path, mode="r") as file:
file.read()
如果要显示已执行单元格的输出,应在不同的单元格(或单元格末尾)中执行要检查的变量。如果它在上下文管理器中(with 子句),它将无法工作。
[1] with open(path, mode="r") as file:
content = file.read()
[2] content
我的代码在 运行 从存储位置读取文件的特定命令后没有显示任何输出。我还是个初学者,所以我有点困惑。将我的代码放在下面
您没有读取您的代码文件,因此它不显示任何输出。
试试这个
path = <path of you file>
file = open(path, mode="r")
file.read()
file.close()
您还可以进一步简化它
with open(path, mode="r") as file:
file.read()
如果要显示已执行单元格的输出,应在不同的单元格(或单元格末尾)中执行要检查的变量。如果它在上下文管理器中(with 子句),它将无法工作。
[1] with open(path, mode="r") as file:
content = file.read()
[2] content