Phazoning
Phazoning

Reputation: 51

Cannot import modules in a same folder

I currently have a problem with my code, which is akin to the one below:

import apples.py as apple

apple.foo()

When I try to import apples.py module (self-made and in the same folder), it raises an error:

ERROR - apples.py module not found.

What can I do? It's a rather heavy script, and putting it into a single script collapses python due to lack of memory.

Upvotes: 1

Views: 68

Answers (1)

sentence
sentence

Reputation: 8913

Suppose you have a directory:

mydir
|----> __init__.py
|----> apples.py
|----> example.py

You can use foo() in apples.py from example.py by:

import apples

apples.foo()

You can read more about modules here.

Upvotes: 2

Related Questions