2

I have a folder structure like:

A/
+-- main.py
+-- bin/
+------ functions.py

I run the code with A as the current working directory.

Within the code of main.py, how do I import the functions.py file?

2
  • 1
    from bin.functions import function1, function2 To be able to do this, make sure bin/ has an __init__.py Commented Jun 6, 2013 at 21:30
  • 1
    yeah.. an empty file called __init__.py Commented Jun 6, 2013 at 21:42

1 Answer 1

0

You need to create an empty file bin/__init__.py. This will tell python that bin is a "package" and should look for modules there.

from bin import functions

If you want to do something like from bin.functions import * you can add which functions you want to load defining them in __init__.py (more here)

# __init__.py
__all__ = ["fun1", "fun2"]
# doing import * will load those 2

You can find more info here.

Sign up to request clarification or add additional context in comments.

1 Comment

Another little question, if I want all of the functions to be imported (like: from hi import *) ?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.