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
然而執(zhí)行出錯(cuò)。。。我想問下,一般python中怎么掛載自己寫的子模塊呢?
3 回答

PIPIONE
TA貢獻(xiàn)1829條經(jīng)驗(yàn) 獲得超9個(gè)贊
layout_format = {}
for filename in os.listdir('mod'):
if filename.endswith('py'):
exec(open(os.path.join('mod',filename)).read())
print(layout_format)
exit()
原來這樣就可以了。。。。JavaScript的eval!=python的eval,對(duì)應(yīng)的是exec
添加回答
舉報(bào)
0/150
提交
取消