0

If i want to use the function hello(), what should i do.

I am using VS Code

So My directory looks like this


project

  • myapp
    • __init__.py (have hello( ) function)
    • test.py
  • run.py

in __init__.py file

def hello():
   print('hello')

in run.py file, if i wrote

from myapp import hello
hello()

it works

However if i try the same thing in test.py, it won't work.

when i searched for answer, someone told me to put sys.path.append(),

i have tried to put un test.py file

import sys
sys.path.append('path\project\myapp')
from myapp import hello
hello()

but still have same error.

abj
  • 1
  • 2
  • Does this answer your question? [Python Packaging with Pytest](https://stackoverflow.com/questions/76177509/python-packaging-with-pytest) – Anton Petrov May 08 '23 at 11:58
  • Never touch `sys.path` unless you're absolutely sure what you're doing. – AKX May 08 '23 at 12:04

2 Answers2

-1

Welp in run.py file

instead of

from myapp import hello

from __init__ import hello
hello()

this works well

abj
  • 1
  • 2
-1

you can use from __init__ import hello or other options given here link