Good day. I'm just starting to get acquainted with Python and I am faced with the problem of uploading my own config.

index.py:

if os.path.exists(config["pagedir"] + params["id"] + ".py"): __import__(string.replace(config["pagedir"], "/", ".") + params["id"]) print page # не работает 

pages / index.py:

 page = { "tpl": "page.html", "title": "index", "html": "<b>Index</b> page" } #print page - работает даже после импорта 

Actually, the question is: how to reach the page?
Thank you in advance.

  • You can ask, why do you need such a terrible construction? What is not satisfied with the usual static import and / or the usual config in yaml (json, xml, etc)? - Ilya Pirogov

1 answer 1

 module = __import__(config["pagedir"].replace("/", ".") + params["id"], fromlist=True) print module.page 
  • Thanks It works. =) - ling