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
returnunless you're returning a value e) no semicolons at end of lines f) consider whether you really need classes at all.assert isisntance(items, dict)instead ofif type(items) != type({})?