Skip to content
Sign upLog in
← Back to Community

Import from folders

Profile icon
RYANTADIPARTHI

I have a folder, and in the folder I have on file, and in the file I have one function.

In main.py, I want to import the function from that file, and from that folder.

I tried all methods of importing, but everything gives an error. Can anyone tell me how to do this correctly, or is it a replit error?

Thanks!

Voters
Profile icon
AnthonyGustafso
Profile icon
RYANTADIPARTHI
Comments
hotnewtop
Profile icon
bendev9

You’d need to do the following:
python from Folder.file import function

Profile icon
RYANTADIPARTHI

@bendev9
i already did that. That's the first thing I did. It didn't work, which is why I'm asking in this question.

Profile icon
bendev9

@RYANTADIPARTHI
, here's another one to try:

import sys sys.path.apped("FULL_PATH_TO_FOLDER") from file import function function()
Profile icon
RYANTADIPARTHI

@bendev9
thanks, but i already figured it out.

Profile icon
ch1ck3n

in the folder just add an __init__.py file with no contents and that might work

Profile icon
RYANTADIPARTHI

@ch1ck3n
it still doesn't work.