从目录导入模块

时间:2017-09-02 06:25:04

标签: python import

我在main.py内部通过' python main.py'执行程序,我在整个程序中使用了一些全局变量。这是目录结构:

.
|-- display
|   |-- __init__.py
|   |-- __init__.pyc
|   |-- view.py
|   `-- view.pyc
|-- engines
|   |-- __init__.py
|   |-- __init__.pyc
|   |-- multithread.py
|   |-- multithread.pyc
|   |-- parse.py
|   `-- parse.pyc
|-- execute.py
|-- global.py
|-- __init__.py
|-- main.py
|-- master_device_list
`-- objects
    |-- arista.py
    |-- arista.pyc
    |-- baseinterface.py
    |-- baseinterface.pyc
    |-- baseplatform.py
    |-- baseplatform.pyc
    |-- brocade.py
    |-- brocade.pyc
    |-- cisco.py
    |-- cisco.pyc
    |-- citrix.py
    |-- citrix.pyc
    |-- initialize.py
    |-- initialize.pyc
    |-- __init__.py
    |-- __init__.pyc
    |-- juniper.py
    |-- juniper.pyc
    |-- ubuntu.py
    |-- ubuntu.pyc
    |-- unknown.py
    `-- unknown.pyc

当我执行时,我收到此错误:

3 directories, 37 files
root@jumpbox:~/staging# 
root@jumpbox:~/staging# python main.py 


Traceback (most recent call last):
  File "main.py", line 77, in <module>
    main()
  File "main.py", line 44, in main
    parse_engine(database,check)
  File "/root/staging/engines/parse.py", line 17, in parse_engine
    ntw_device.append(device)
NameError: global name 'ntw_device' is not defined

ntw_device是main.py中的全局变量。我需要哪些重要声明来完成这项工作?

0 个答案:

没有答案