How to open a file?

Question:
How to open a file
Repl link:
Lpython

code snippet

You can open a file by clicking on it.

I suppose you are using python

you can use open() to open a file

it’s a long story if you want to truely understand this function so better google it :slight_smile:

4 Likes

If you want to open a file, there are multiple ways:

  • On the File sidebar, press your desired file
  • Press “New Tab” in the workspace, then type the name of your desired file

In your Python code, you could do:

my_writable_file = open("myfile.txt","w") # the w means only writable
my_writable_file.write("myfile.txt's contents!") # the .write replaces the file's contents or creates a new file with the content
my_readable_file = open("myfile.txt","r") # the r means only readable
print(my_readable_file.read()) # the .read looks at the file's content.

Hope this helps!

4 Likes

Hi!
To open a file, click on the file name in the side bar (right side). Or if you want to open the file in Python, paste this code

with open("filename.txt") as f:
   #code here...