Jestem nowy w programowaniu Pythona. Mam utworzyć pakiet o nazwie kuchnia. Chcę importować plik klasy poprzez plik __init__.py
.ImportError: Brak modułu o nazwie "" podczas importowania klasy w pliku __init__.py Python
Jestem python wersja: 3.3.2 Platforma
OS: Windows
Fridge.py złożyć
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
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
Są to pliki, jest miejsce zamieszkania w kuchni jest pakiet
import Kitchen
Podczas wykonywania tego polecenia
otrzymuję następujący błąd
Traceback (most recent call last):
File "<pyshell#50>", line 1, in <module>
import Kitchen
File "E:\Mani\Learnings\Phython\Kitchen\__init__.py", line 1, in <module>
from Courses import Courses
ImportError: No module named 'Courses'
proszę mi pomóc w jaki sposób sobie z tym poradzić a także proszę dać mi znać, gdzie poszło nie tak
Wiem, że jesteś nowicjuszem w Pythonie, ale a) nie sprawdzaj typów b) nie używaj zmiennych domyślnych argumentów c) używaj formatu underscore_separated dla nazw d) nie potrzebujesz ' return', chyba że zwracasz wartość e) brak średników na końcu linii f) rozważ, czy naprawdę potrzebujesz zajęć w ogóle. –
@DanielRoseman: Dzięki za cenne sugestie –
@DanielRoseman> nie sprawdzaj typów
warvariuc