Ask coding questions

← Back to all posts
Import from folders
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
RYANTADIPARTHI
Comments
hotnewtop
bendev9

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

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.

bendev9

@RYANTADIPARTHI, here's another one to try:

RYANTADIPARTHI

@bendev9 thanks, but i already figured it out.

ch1ck3n

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

RYANTADIPARTHI

@ch1ck3n it still doesn't work.