Home > other >  Jupiter Notebook in vs code: python command not showing/ reading file from memory
Jupiter Notebook in vs code: python command not showing/ reading file from memory

Time:01-26

my code is not showing any output after running specific commands for reading a file from storage location. I'm still a beginner so i'm little confused. Dropping my code here below

enter image description here

CodePudding user response:

You are not reading the file your code, hence it does not show any output.

Try this

path = <path of you file>
file = open(path, mode="r")
file.read()
file.close()

You can also simplify it further

with open(path, mode="r") as file:
    file.read()

CodePudding user response:

If you want to display the output of an executed cell, you should execute the variable you want to inspect in a different cell (or at the end of a cell). It wont work if it is inside the context manager (with clause).

[1] with open(path, mode="r") as file:
       content = file.read() 

[2] content

  •  Tags:  
  • Related