【发布时间】:2018-09-04 09:05:30
【问题描述】:
我在 python 中有一个名为 tb_batch 的模块。内容是:
m_d = dt.datetime.now().strftime('%B') + '_' + str(dt.datetime.now().year)
当我尝试将此变量导入另一个 python 程序时,
from tb_batch import m_d
它抛出错误:
AttributeError: module 'tb_batch' has no attribute 'm_d'
我做错了什么?
【问题讨论】:
-
无法重现错误,在我这边工作得很好(
tb_batch.py包含import datetime as dt和你引用的行)。您可以为我们创建一个显示错误的Minimal, Complete, and Verifiable example 吗? -
我正在使用 jupyter notebook。当我在 Visual Studio 代码中尝试相同的代码时,它可以完美运行
-
AttributeError Traceback (most recent call last) <ipython-input-22-5e9764232617> in <module>() 1 import tb_batch ----> 2 print(tb_batch.tb_path) AttributeError: module 'tb_batch' has no attribute 'tb_path' -
AttributeError Traceback (most recent call last) <ipython-input-20-e883f7ca7e7a> in <module>() ----> 1 tb_batch.m_d AttributeError: module 'tb_batch' has no attribute 'm_d' -
我对@987654322@ 没有太多经验。请标记它,以便具有相关专业知识的人更容易找到您的问题。
标签: python jupyter-notebook python-import