import error.py问题
单独运行utils.py没有问题
运行base.py则ModuleNotFoundError: No module named 'error'
运行2个脚本都是在utils.py脚本中 import error.py
utils.py
# coding:utf-8 """常用的公共函数""" import os import error def check_file(path): if not os.path.exists(path): raise error.NotPathError(f'not found {path}') if not path.endswith('.json'): # 不是json文件名字 raise error.FormatError('need json format') if not os.path.isfile(path): raise error.NotFileError('this is not a file') if __name__ == '__main__': gift_path = os.path.join('../', 'storage', 'gift.json') user_path = os.path.join('../', 'storage', 'user.json') check_file(gift_path) check_file(user_path)
base.py
# coding:utf-8 """ 1:导入user.json 文件检查 2:导入gift.json 文件检查 """ import os # from common import error from common.utils import check_file class Base(object): def __init__(self, user_json, gift_json): self.user_json = user_json self.gift_json = gift_json self.__check_user_json() self.__check_gift_json() def __check_user_json(self): # 路径不存在 check_file(self.user_json) def __check_gift_json(self): check_file(self.gift_json) if __name__ == '__main__': gift_path = os.path.join(os.getcwd(), 'storage', 'gift.json') user_path = os.path.join(os.getcwd(), 'storage', 'user.json') print(gift_path) print(user_path) # base = Base(user_path, gift_path)
11
收起
正在回答 回答被采纳积分+1
1回答
Python全能工程师
- 参与学习 人
- 提交作业 16247 份
- 解答问题 4470 个
全新版本覆盖5大热门就业方向:Web全栈、爬虫、数据分析、软件测试、人工智能,零基础进击Python全能型工程师,从大厂挑人到我挑大厂,诱人薪资在前方!
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星