cari

Rumah  >  Soal Jawab  >  teks badan

python中如何挂载自己写的在子目录下的模块?

main.py

layout_format = {}for filename in os.listdir('mod'):    if filename.endswith('py'):        for line in open(os.path.join('mod',filename)):            eval(line)print(layout_format)exit()

mod/md.py

markdown_template = "# %(title)s\r\nAuthor: %(author)s\r\nCreate Date: %(created_time)s\r\nLast Update: %(updated_time)s\r\n\r\n%(content)s\r\n"def markdown(self):
    return markdown_template % self
layout_format['md'] = markdown

然而执行出错。。。我想问下,一般python中怎么挂载自己写的子模块呢?


巴扎黑巴扎黑3026 hari yang lalu641

membalas semua(1)saya akan balas

  • 面对疾风吧

    面对疾风吧2016-11-09 16:56:43

    layout_format = {}


    for filename in os.listdir('mod'):

        if filename.endswith('py'):

            exec(open(os.path.join('mod',filename)).read())


    print(layout_format)

    exit()


    balas
    0
  • Batalbalas