Splitting my code into multiple files in Python 3
Question: I wish to split my code into multiple files in Python 3.

I have the following files:

    
    
    /hello
        __init__.py
        first.py
        second.py
    

Where the contents of the above files are:

**`first.py`**

    
    
    from hello.second import say_hello
    
    say_hello()
    

**`second.py`**

    
    
    def say_hello():
        print("Hello World!")
    

But when I run:

    
    
    python3 first.py
    

while in the `hello` directory I get the following error:

    
    
    Traceback (most recent call last):
      File "first.py", line 1, in <module>
        from hello.second import say_hello
    ImportError: No module named 'hello'
    


Answer: Swap out

    
    
    from hello.second import say_hello
    

for

    
    
    from second import say_hello
    

Your default Python path will include your current directory, so importing
straight from `second` will work. You don't even need the `__init__.py` file
for this. You _do_ , however, need the `__init__.py` file if you wish to
import from outside of the package:

    
    
    $ python3
    >>> from hello.second import say_hello
    >>> # Works ok!
    

