search

Home  >  Q&A  >  body text

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中怎么挂载自己写的子模块呢?


巴扎黑巴扎黑3027 days ago644

reply all(1)I'll reply

  • 面对疾风吧

    面对疾风吧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()


    reply
    0
  • Cancelreply