1

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.

1 Answer 1

2

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.

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

5 Comments

with directory you mean the folder? I'm quite new on what that term is (also, my English isn't the best on programming, which doesn't help at all). Sorry for the inconvenience
Yes, it is. mydir is the folder containing three files.
*but without the init.py file. I don't know if it's relevant or not. Also, excuse the split message, I'm typing on phone and, oh, well...
It is relevant to make Python treat directories containing the file as packages. So, not in your case.
Then we are in the starting point again (I'll upload a better example as soon as I get home, for I am currently on my way and I don't expect to arrive in less than an hour and a half

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.