How to access separate python file in another python replit to store data like a data frame

**Question:**I am writing student grading program it works but I want to store results in seperate file in another replit program file like a data frame. how does first replit progam access second to do this? Reason I need another second file storing program is because students will take test at seperate times so I need to store each result in seperate file to get total for whole class.

code snippet

Can you explain your situation better, I cannot understand.


Could you be a bit more clear and elaborate a little bit (for instance what exactly do you mean by “dataframe”)?
If you’ve made a Repl for this and started on it, share it as well.

1 Like

Hey, @panagranit welcome to the forums!

Can you please provide a link to the repl? This way it is easier for staff and members of the community to help you!

Also see this guide on how to share your code:

1 Like

I assume what you want is to save the output into a file, or multiple files
You can use with open(file name, ‘w’) as f: f.write(output)
however I still do not understand what you want exactly

1 Like

I am non sure it is possible to import a file in a REPL from another repl without going throught a GIT, copy&paste he file or some overly complicated always-on server.
Would be great thought is possible

I want to put student_answers in to file that is not current directory. the student_answers will go in
a file that will be a python program that will take student answers and put in dataframe python

Hello @panagranit if you have a function in a separate python file, you can run this code: The code that needs to be accessed:

def Hello_World():
    print("Hello World") The Code that will run the Hello_World function (in another python file):

from Hello_World import Hello_World #Imports the Hello_World Function


Hello World

I hope this helps!


1 Like

Is the file in same directory as Hello_World? How to access files not in your main program directory like one you created months ago on something else ? the file is replit file.

You can’t do that in Replit.

well you can link it but can you make it run in the link as a separate program.? in other words do you start a program on one replit page and then it references another Replit page URL can you make that second one do something with data from the first?

OK so I see a solution to my problem. Because the students are taking the test at different times what I’ll do is store it students answer in a text file. When they finish the program their answers will be stored in a text file. Then the next student can take the test asynchronously and put their answers in and it will be stored as a text file at the end of the day or whatever I should have multiple text files with different names associated with them that I can do an analysis on. I don’t have to get a separate replit webpage for that. hopefully the python program can create a new text file to store the answers and each time without it being it being erased every time when you start the pram up.

While I do not understand your most recent comment, The python file does NOT need to be in the same directory. For example if the file is in a folder called “program files,” (the folder is in the same directory as the file) you would do it like this (I think):

from program_files/hello_world import hello_world

I will need to test this. I will get back to you when I do!

Correct me if I’m wrong but that’s invalid syntax.

Oh shoot, you are right. Let me brainstorm this as I haven’t done this yet… hold on!

based on my knowledge, underscores aren’t possible in python library names and if a library is uploaded to pypi with an underscore it will be converted to a hyphen.

1 Like

Okay, I brainstormed and this is how to do it with the hello_world file in Program Files folder:

from Program_Files import hello_world 

See my code here:

1 Like

For shorthand I think you can change it to this:

from Program_Files import hello_world as hw

That would work. I didn’t do that for clarity of showing the program, but you are 100% correct.

1 Like