Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

How do I read and use files from my computer in the Python compiler???

0 votes
asked Mar 20, 2019 by Priscilla Houck (120 points)

Ok so I want to start messing around with .txt files and I for some reason have a .txt file with almost every word ever in it and I was hoping to have some help using the things in said file to spit out random words and numbers and symbols for totally no reason. Oh yeah and I want to do this in python because I'm still somewhat of a noob.

Thx for the help,

C++la

(It's a pun I'm sorry)

3 Answers

+1 vote
answered Mar 21, 2019 by Admin (5,100 points)
You can create new file by pressing Ctrl + M in IDE. More details on creating new file is available at https://www.onlinegdb.com/blog/introducing-multifile-project/

Once you created new file, you can read it using program. Sample code is available at
https://onlinegdb.com/S1-UFQbON
0 votes
answered Sep 1, 2019 by NavarroAndorid (360 points)
In order to read a file from a program you need to include it in the same project.  For example, you can have the data in data.txt and your code in myCode.  You can add additional files to your project using Ctrl + M.  When you list your projects, you will only be able to see the projects names but not the file they contain.  If you want to do so, you can download the project to your computer and unzip it.
0 votes
answered Apr 9, 2020 by andr14142 (180 points)
Noway. You cannot read/write files from your computer directly. You can upload the file from your computer to server with ways below. After that you can read/write files included in your project.
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...