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

0 votes
asked Mar 20 by (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)

2 Answers

0 votes
answered Mar 21 by (3,770 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 by (260 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.
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.
...