Ask coding questions

← Back to all posts
How do you get a file path from repl.it?
GrantKeo

How do you get a file path on repl.it?

I'm guessing that there's some trick I don't know when getting a file path through repl.it. I want to use folders to organize my files, such as the path for a txt file.

E.g.:

So what am I missing? I'm guessing it has something to do with the little "(home)/" at the topleft corner of "my repls," but what is it exactly? (And by the way, can you please provide the answer in Python 3? I use that language for everything.)

Thanks in advance!

Answered by AlexanderBirabe [earned 5 cycles]
View Answer
Voters
Utterubbish
xaiyeon
divyarajparmar
GlowstikkYT
GrantKeo
Comments
hotnewtop
AlexanderBirabe

You can only access files in the same repl unless you make an API or something like that.

GrantKeo

@AlexanderBirabe Well, how do I do that in that case?

AlexanderBirabe

@GrantKeo In python you would just do:

To open the file 'filename.txt' in read mode (as long as it's in the same folder.

If say filename.txt was in a folder called 'myFolder' and myFolder was in the same folder as the script you are using to reference it, it would be:

https://www.w3schools.com/python/python_file_handling.asp

GrantKeo

@AlexanderBirabe I'll try that then.

GrantKeo

@AlexanderBirabe But how do you upload a .py file from the same project?

AlexanderBirabe

@GrantKeo By upload to you mean run? If so, you do it like this:

where filename.py is the code you want to run.

GrantKeo

@AlexanderBirabe However, import filename does not work when the py file is inside a folder. I'm asking how do you import a py file from another folder using repl.it?

AlexanderBirabe

@GrantKeo Oh ok, you do that like this:

GrantKeo

@AlexanderBirabe Ah, thanks!

Party-Hatter

@GrantKeo have you found a way to make it into an input? like import foldername.(variable of whatever file you want to open within the folder)

ZenoxHosting

Yeah I was wondering if there was a way to access files inside a repl project. I am doing os.chdir('mainbank.json') and it says that it is not a directory. I am pretty new to coding with Repl so it would be nice if anyone could help me out. Thanks :D

Pecoretta

have you solved your issue? if yes, how? @ZenoxHosting

SharpRhyme

@ZenoxHosting Please help

ash15khng

The (home)/ thing is just a way for you to find your repls and I'm quite sure it's just for you to organise your repls which means you can't access stuff from other repls.

GrantKeo

@ash15khng I had not actually wanted to access from other files, but I want to know the file path inside a repl.it project.