How to import a class in pynecone?

85 Views Asked by At

I'm trying to import a class in another python class in my pynecone project. It's giving me error.

import Constants ---> Giving error 

ModuleNotFoundError: No module named 'Constants'

Edit: Folder structure:

enter image description here

From helloworld.py, I'm trying to import Constants. How can this be done?

2

There are 2 best solutions below

1
tim the fiend On BEST ANSWER

The way it's being imported within the library is

from pynecone import constants
0
AlexOAD On

You can simple write:

from helloworld import Constants

Other options is use the __init__.py file to initialize the modules. You can write from helloworld import Constants as const (as is optional) and then, in the helloworld.py file write at the top from helloworld import const or relative import from . import const