Skip to content
Sign UpLog In
This post is read-only. Explore Repls and connect with other creators on Community.View Community
The info in this post might be out of date, check out our docs instead. View docs
2

Import from folders

RYANTADIPARTHI
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!

1 year ago

Voters

Comments

TopNew
1
bendev9
bendev9

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

1 year ago
1
RYANTADIPARTHI
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.

1 year ago
1
bendev9
bendev9

@RYANTADIPARTHI
, here's another one to try:

import sys sys.path.apped("FULL_PATH_TO_FOLDER") from file import function function()
1 year ago
1
RYANTADIPARTHI
RYANTADIPARTHI

@bendev9
thanks, but i already figured it out.

1 year ago
1
ch1ck3n
ch1ck3n

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

1 year ago
1
RYANTADIPARTHI
RYANTADIPARTHI

@ch1ck3n
it still doesn't work.

1 year ago
Load more