How to import local files in replit?

Question: how to import local files in replit mobile app

Repl link/Link to where the bug appears:

Screenshots, links, or other helpful context:

code snippet

HI! Welcome to the forums. In python, you can import functions from other files. For example. This is how our files are placed:

In functions, we have this code:

def foo():
     print('Hello, World!')

to get our function, foo() into our, we put this code into

import functions # no ".py" necessary

and the output:

Hello, World!

Stuff I am not totally sure about:

If you have in a different location then, you would also need to include the file. For example, this is our file tree:

Then you would import it with a period between the folder and the functions:

import foldername.functions as functions # without the "as," you would need to type

(Thanks @QwertyQwerty88. I edited this post)

If you want more ways to import from a folder, see @QwertyQwerty88’s post below.

I hope this helps!


No, you have to import it like this:

import foldername.functions
# or
import foldername.functions as functions
# or
from foldername import functions

I edited my original post.