Sono nuovo alla programmazione Python. Ho creato un pacchetto chiamato cucina. Voglio importare un file di classe attraverso il file __init__.py
.ImportError: nessun modulo chiamato '' while Importa classe nel file __init__.py Python
Sono versione di Python: piattaforma 3.3.2
SO: Windows
Fridge.py presentare
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
Si tratta di file è risiedeva a Kitchen è il pacchetto
import Kitchen
Durante l'esecuzione di questo comando
sto ottenendo seguente errore
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'
Please help me come gestire questo e per favore fatemi sapere dove sono andato storto
So che sei nuovo in Python, ma a) non controllare i tipi b) non utilizzare argomenti di default mutabili c) usa il formato underscore_separated per i nomi d) non c'è bisogno di ' return' a meno che tu non stia restituendo un valore e) no punto e virgola alla fine delle righe f) considera se hai davvero bisogno di classi. –
@DanielRoseman: Grazie per i preziosi suggerimenti –
@DanielRoseman> non controllare i tipi
warvariuc