0

I have a code in Python-Part/Modules&Packages/salute.py

def say_hello(name):
    print(f'Hello {name}')


fruits = {
    'name': 'Grapes',
    'color': 'Green'
}

I have a code in Python-Part/Modules&Packages/my_module.py

import salute
from salute import fruits

salute.say_hello('Rafi')

print(fruits['name'])

When I put them in the Python-Part directory they were working fine but when I move them into Python-Part/Modules&Packages, my_module.py is not importing salute.py.

Now, I want to know why this is happening and how to overcome from it?

Tomerikoo
  • 15,737
  • 15
  • 35
  • 52
Sowat Rafi
  • 31
  • 2
  • 1
    Welcome to SO. Please consider including whatever error traceback you get in your post. – ewong Sep 29 '20 at 09:47
  • The information provided is not enough to give a definitive answer, other than guessing. Please see the [mcve] and [ask] pages how to help us help you. In specific, how do you run your code? – MisterMiyagi Sep 29 '20 at 09:49
  • 4
    Try adding `_init__.py` file in every folder – Ajay A Sep 29 '20 at 09:49

1 Answers1

1

The __init__.py files are required to make Python 2 treat the directories as containing packages; this is done to prevent directories with a common name, such as string, from unintentionally hiding valid modules that occur later on the module search path.

In the simplest case, __init__.py can just be an empty file.

So, try to add __init__.py to package directories you intend to use.

Ava_Katushka
  • 145
  • 8