ImportError:没有名为'';在Python文件中导入类时
我是python编程新手。我创建了一个名为“厨房”的软件包。我想通过ImportError:没有名为'';在Python文件中导入类时,python,import,Python,Import,我是python编程新手。我创建了一个名为“厨房”的软件包。我想通过\uuu init\uuuu.py文件导入一个类文件 我是python版本:3.3.2 操作系统平台:windows 冰箱.py class Fridge: def __init__(self, items={}): """Optionally pass in an initial dictionary of items""" if type(items) != type({}):
\uuu init\uuuu.py
文件导入一个类文件
我是python版本:3.3.2
操作系统平台:windows
冰箱.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());
课程.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());
\uuuu init\uuuuu.py
from Courses import Courses
from Fridge import Fridge
这些是存放在厨房的文件是包
import Kitchen
执行此命令时,我遇到以下错误
回溯(最近一次呼叫最后一次):
文件“”,第1行,在
进口厨房
文件“E:\Mani\Learnings\Phython\Kitchen\uuuu init\uuuuuu.py”,第1行,在
从课程导入课程
导入错误:没有名为“课程”的模块
请帮助我如何处理此问题,同时请告诉我哪里出了问题您正在使用Python 3。做
from .Courses import Courses
from .Fridge import Fridge
Python2会在同一目录中查找课程
模块,但Python3会在站点包中查找课程
模块——显然,它不在那里
p.S.“Phython”-听起来很有趣;) 谢谢你的回复。让我检查并命名小写字母中的模块。非常感谢!我花了几个小时才找到解决方案(你的答案)。。。我想知道为什么这样的细节不得不从一个版本变为另一个版本。TT@EduardoReis这是一个长期存在的问题,在Python3中得到了修复:@BenjaminR是的,我认为Python文档很糟糕。如果您能在PHP中评论一些用户提供的值得注意的示例/评论,那就太好了。我知道您是Python新手,但是A)不要检查类型B)不要使用可变的默认参数C)使用名字的“低于分数的格式”不需要<代码>返回< /代码>除非你返回一个值e)在行的末尾没有分号(F)考虑你是否真的需要上课。suggestions@DanielRoseman>不检查类型<使用
assert isisntance(items,dict)
而不是if type(items)!=键入({})
?