I am new to python programming. I have create package called kitchen. I want import a class file through __init__.py file.
I am python version : 3.3.2
OS platform : windows
Fridge.py
class Fridge:   
    def __init__(self, items={}):
        """Optionally pass in an initial dictionary of items"""
        if type(items) != type({}):
            raise TypeError("Fridge requires a dictionary but was given %s" %
    type(items))
        self.items = items
        return
    def _Get_Items(self):
        print(self.items);
    def _Get_Added_Values(self,lst):
        values =0;
        print(len(lst));
        for index in lst:
            values += index;
        return values
    def _Get_Seperetor(self,str1,lst):
        str1=str1.join(lst);
        return str1;
    def _Get_Keys(self):
        print(self.items.keys());
Courses.py file
class Courses:
    def __init__(self, items=[]):
        """Optionally pass in an initial dictionary of items"""
        if type(items) != type([]):
            raise TypeError("Fridge requires a dictionary but was given %s" %
    type(items))
        self.items = items
        return
    def _Get_Items(self):
        print(self.items);
    def _Get_Seperetor(self,str1,lst):
        str1=str1.join(lst);
        return str1;
    def _Get_Keys(self):
        print(self.items.keys());
__init__.py
from Courses import Courses
from Fridge import Fridge
These are files is resided at Kitchen is the package
import Kitchen
While executing this command I am getting following error
Traceback (most recent call last): File "", line 1, in import Kitchen File "E:\Mani\Learnings\Phython\Kitchen__init__.py", line 1, in from Courses import Courses ImportError: No module named 'Courses'
Please help me how to handle this and also please let me know where I went wrong
You are using Python 3. Do
from .Courses import Courses
from .Fridge import Fridge
Python 2 would look for Courses module in the same dir, but Python 3 looks for Courses module in site packages - and, obviously, it's not there.
P.S. "Phython" - sounds interesting ;)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With