Heim > Fragen und Antworten > Hauptteil
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中怎么挂载自己写的子模块呢?
代言2016-11-09 10:04:44
layout_format = {} for filename in os.listdir('mod'): if filename.endswith('py'): exec(open(os.path.join('mod',filename)).read()) print(layout_format) exit()