How should I implement my package so I can write the following.
Suppose my Module is called Market. It is a folder in the working directory of my python script called goShopping.py
In my goShopping.py I want to be able to write the following piece of code:
import market as mk
B = mk.Banana(0.99)
A = mk.Apple(1.10)
A.buy()
B.buy()
Where Banana and Apple are objects in some file in my Module.
How should the Module market be written?
Let's say that I have a file in the Module folder called fruits.py, There I define Banana and Apple class. I know I can write the above code as follows:
import market.fruits as mk
B = mk.Banana(0.99)
A = mk.Apple(1.10)
A.buy()
B.buy()
But I don't want that.
As a solution I thought about having some declaration in __init__.py
(the __init.py
inside the market folder) like this:
from fruits import Apple,Banana.
But I get the following error:
AttributeError: module 'market' has no attribute 'Banana'
From line:
B = mk.Banana(0.99)
How should I structure and what should I write to be able expose the objects as I want?
I am using Pythonista for iOS. I wonder if this is the problem.