{"id":25186,"date":"2022-12-08T14:32:39","date_gmt":"2022-12-08T09:02:39","guid":{"rendered":"https:\/\/jassweb.com\/solved\/solved-print-a-sentence-with-placeholder-and-function-from-an-external-file-problem-with-importing-forms-using-and-retrieving-content\/"},"modified":"2022-12-08T14:32:39","modified_gmt":"2022-12-08T09:02:39","slug":"solved-print-a-sentence-with-placeholder-and-function-from-an-external-file-problem-with-importing-forms-using-and-retrieving-content","status":"publish","type":"post","link":"https:\/\/jassweb.com\/solved\/solved-print-a-sentence-with-placeholder-and-function-from-an-external-file-problem-with-importing-forms-using-and-retrieving-content\/","title":{"rendered":"[Solved] Print a sentence with placeholder and function from an external file. Problem with importing forms, using and retrieving content"},"content":{"rendered":"<p> [ad_1]<br \/>\n<\/p>\n<div id=\"answer-73191220\" class=\"answer js-answer accepted-answer js-accepted-answer\" data-answerid=\"73191220\" data-parentid=\"73161459\" data-score=\"4\" data-position-on-page=\"1\" data-highest-scored=\"1\" data-question-has-accepted-highest-score=\"1\" itemprop=\"acceptedAnswer\" itemscope itemtype=\"https:\/\/schema.org\/Answer\">\n<div class=\"post-layout\">\n<div class=\"votecell post-layout--left\"><\/div>\n<div class=\"answercell post-layout--right\">\n<div class=\"s-prose js-post-body\" itemprop=\"text\">\n<p>Move the dictionaries in dicts.py and create a class in template.py to return required template.You can create as many templates as you want in templates.py.<\/p>\n<h2><strong>dicts.py<\/strong><\/h2>\n<pre><code>teams = {...}\n   \nnouns = {...}\n\narticle_words = {...}\n<\/code><\/pre>\n<h2><strong>template.py<\/strong><\/h2>\n<pre><code>from grammer import getArticle\nimport random\n\nclass Template():\n\n    def __init__(self,**kwargs):\n        self.__dict__.update(kwargs)\n\n        # must define other variables like article which are used\n        # in templates irrespective of the arguments passed\n\n        if self.subject:\n            self.article = getArticle(subject=self.subject)\n\n    def return_template(self):\n        test_template_list = [\"Bla bla bla {subject} {article}\", \"Again bla bla bla {subject}\"]\n        test_template = random.choice(test_template_list)\n\n        place_holders = ['{subject}','{article}', ]\n\n        for i in place_holders:\n            if i in test_template:\n                test_template=test_template.replace(i,(self.__dict__[i.lstrip(\"{\").rstrip(\"}\")]))\n        \n        return test_template\n<\/code><\/pre>\n<h2><strong>grammer.py<\/strong><\/h2>\n<pre><code>from dicts import article_words, nouns\n\ndef getArticle(subject):\n    for key, value in article_words.items():\n        if nouns[subject] == value:\n            return key\n<\/code><\/pre>\n<h2><strong>main.py<\/strong><\/h2>\n<pre><code>from tkinter import *\nfrom tkinter import ttk\nfrom template import Template\nfrom dicts import teams\n\nroot = Tk()\nroot.geometry(\"420x150\")\n\ntournament=ttk.Combobox(root, width = 18)\ntournament.place(x=15, y=15)\ntournament['value'] = [\"Serie A\", \"Serie B\"]\ntournament.set(\"Tournament\")\n\ndef on_tournament_selected(event):\n    team.delete(0,'end') \n\n    req_teams = [] \n    sel_tournament = tournament.get() \n\n    for key,value in teams.items():\n        if value['Tournament'] == sel_tournament:\n            req_teams.append(key)\n\n    team.config(values=req_teams)\n\ntournament.bind(\"&lt;&lt;ComboboxSelected&gt;&gt;\", on_tournament_selected)\n\nteam=ttk.Combobox(root, width = 18)\nteam.place(x=215, y=15)\nteam.set(\"Teams\")\n\ntext = Text(root,width=43,height=2)\ntext.place(x=15, y=50)\n\ndef printTeam():\n    template1 = Template(subject=team.get()) # pass keyword arguments\n    text.insert(END, template1.return_template())\n\nbutton2 = Button(root, text=\"Print\", command = printTeam)\nbutton2.pack()\nbutton2.place(x=15, y=100)\n\nroot.mainloop()\n<\/code><\/pre>\n<p>The error was due to circular imports in your files.<\/p>\n<\/p><\/div>\n<div class=\"mt24\"><\/div>\n<\/div>\n<p>            <span class=\"d-none\" itemprop=\"commentCount\">24<\/span> <\/p><\/div>\n<\/div>\n<p>[ad_2]<\/p>\n<p>solved Print a sentence with placeholder and function from an external file. Problem with importing forms, using and retrieving content <\/p>\n","protected":false},"excerpt":{"rendered":"<p>[ad_1] Move the dictionaries in dicts.py and create a class in template.py to return required template.You can create as many templates as you want in templates.py. dicts.py teams = {&#8230;} nouns = {&#8230;} article_words = {&#8230;} template.py from grammer import getArticle import random class Template(): def __init__(self,**kwargs): self.__dict__.update(kwargs) # must define other variables like article &#8230; <a title=\"[Solved] Print a sentence with placeholder and function from an external file. Problem with importing forms, using and retrieving content\" class=\"read-more\" href=\"https:\/\/jassweb.com\/solved\/solved-print-a-sentence-with-placeholder-and-function-from-an-external-file-problem-with-importing-forms-using-and-retrieving-content\/\" aria-label=\"More on [Solved] Print a sentence with placeholder and function from an external file. Problem with importing forms, using and retrieving content\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[320],"tags":[1676,349,362,768],"class_list":["post-25186","post","type-post","status-publish","format-standard","hentry","category-solved","tag-module","tag-python","tag-string","tag-tkinter"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>[Solved] Print a sentence with placeholder and function from an external file. Problem with importing forms, using and retrieving content - JassWeb<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/jassweb.com\/solved\/solved-print-a-sentence-with-placeholder-and-function-from-an-external-file-problem-with-importing-forms-using-and-retrieving-content\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"[Solved] Print a sentence with placeholder and function from an external file. Problem with importing forms, using and retrieving content - JassWeb\" \/>\n<meta property=\"og:description\" content=\"[ad_1] Move the dictionaries in dicts.py and create a class in template.py to return required template.You can create as many templates as you want in templates.py. dicts.py teams = {...} nouns = {...} article_words = {...} template.py from grammer import getArticle import random class Template(): def __init__(self,**kwargs): self.__dict__.update(kwargs) # must define other variables like article ... Read more\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jassweb.com\/solved\/solved-print-a-sentence-with-placeholder-and-function-from-an-external-file-problem-with-importing-forms-using-and-retrieving-content\/\" \/>\n<meta property=\"og:site_name\" content=\"JassWeb\" \/>\n<meta property=\"article:published_time\" content=\"2022-12-08T09:02:39+00:00\" \/>\n<meta name=\"author\" content=\"Kirat\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Kirat\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-print-a-sentence-with-placeholder-and-function-from-an-external-file-problem-with-importing-forms-using-and-retrieving-content\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-print-a-sentence-with-placeholder-and-function-from-an-external-file-problem-with-importing-forms-using-and-retrieving-content\/\"},\"author\":{\"name\":\"Kirat\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31\"},\"headline\":\"[Solved] Print a sentence with placeholder and function from an external file. Problem with importing forms, using and retrieving content\",\"datePublished\":\"2022-12-08T09:02:39+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-print-a-sentence-with-placeholder-and-function-from-an-external-file-problem-with-importing-forms-using-and-retrieving-content\/\"},\"wordCount\":89,\"publisher\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\"},\"keywords\":[\"module\",\"python\",\"string\",\"tkinter\"],\"articleSection\":[\"Solved\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-print-a-sentence-with-placeholder-and-function-from-an-external-file-problem-with-importing-forms-using-and-retrieving-content\/\",\"url\":\"https:\/\/jassweb.com\/solved\/solved-print-a-sentence-with-placeholder-and-function-from-an-external-file-problem-with-importing-forms-using-and-retrieving-content\/\",\"name\":\"[Solved] Print a sentence with placeholder and function from an external file. Problem with importing forms, using and retrieving content - JassWeb\",\"isPartOf\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#website\"},\"datePublished\":\"2022-12-08T09:02:39+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-print-a-sentence-with-placeholder-and-function-from-an-external-file-problem-with-importing-forms-using-and-retrieving-content\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/jassweb.com\/solved\/solved-print-a-sentence-with-placeholder-and-function-from-an-external-file-problem-with-importing-forms-using-and-retrieving-content\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-print-a-sentence-with-placeholder-and-function-from-an-external-file-problem-with-importing-forms-using-and-retrieving-content\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/jassweb.com\/solved\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"[Solved] Print a sentence with placeholder and function from an external file. Problem with importing forms, using and retrieving content\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/jassweb.com\/solved\/#website\",\"url\":\"https:\/\/jassweb.com\/solved\/\",\"name\":\"JassWeb\",\"description\":\"Build High-quality Websites\",\"publisher\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/jassweb.com\/solved\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\",\"name\":\"Jass Web\",\"url\":\"https:\/\/jassweb.com\/solved\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png\",\"contentUrl\":\"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png\",\"width\":693,\"height\":132,\"caption\":\"Jass Web\"},\"image\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31\",\"name\":\"Kirat\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1775798750\",\"contentUrl\":\"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1775798750\",\"caption\":\"Kirat\"},\"sameAs\":[\"http:\/\/jassweb.com\"],\"url\":\"https:\/\/jassweb.com\/solved\/author\/jaspritsinghghumangmail-com\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"[Solved] Print a sentence with placeholder and function from an external file. Problem with importing forms, using and retrieving content - JassWeb","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/jassweb.com\/solved\/solved-print-a-sentence-with-placeholder-and-function-from-an-external-file-problem-with-importing-forms-using-and-retrieving-content\/","og_locale":"en_US","og_type":"article","og_title":"[Solved] Print a sentence with placeholder and function from an external file. Problem with importing forms, using and retrieving content - JassWeb","og_description":"[ad_1] Move the dictionaries in dicts.py and create a class in template.py to return required template.You can create as many templates as you want in templates.py. dicts.py teams = {...} nouns = {...} article_words = {...} template.py from grammer import getArticle import random class Template(): def __init__(self,**kwargs): self.__dict__.update(kwargs) # must define other variables like article ... Read more","og_url":"https:\/\/jassweb.com\/solved\/solved-print-a-sentence-with-placeholder-and-function-from-an-external-file-problem-with-importing-forms-using-and-retrieving-content\/","og_site_name":"JassWeb","article_published_time":"2022-12-08T09:02:39+00:00","author":"Kirat","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Kirat","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/jassweb.com\/solved\/solved-print-a-sentence-with-placeholder-and-function-from-an-external-file-problem-with-importing-forms-using-and-retrieving-content\/#article","isPartOf":{"@id":"https:\/\/jassweb.com\/solved\/solved-print-a-sentence-with-placeholder-and-function-from-an-external-file-problem-with-importing-forms-using-and-retrieving-content\/"},"author":{"name":"Kirat","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31"},"headline":"[Solved] Print a sentence with placeholder and function from an external file. Problem with importing forms, using and retrieving content","datePublished":"2022-12-08T09:02:39+00:00","mainEntityOfPage":{"@id":"https:\/\/jassweb.com\/solved\/solved-print-a-sentence-with-placeholder-and-function-from-an-external-file-problem-with-importing-forms-using-and-retrieving-content\/"},"wordCount":89,"publisher":{"@id":"https:\/\/jassweb.com\/solved\/#organization"},"keywords":["module","python","string","tkinter"],"articleSection":["Solved"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/jassweb.com\/solved\/solved-print-a-sentence-with-placeholder-and-function-from-an-external-file-problem-with-importing-forms-using-and-retrieving-content\/","url":"https:\/\/jassweb.com\/solved\/solved-print-a-sentence-with-placeholder-and-function-from-an-external-file-problem-with-importing-forms-using-and-retrieving-content\/","name":"[Solved] Print a sentence with placeholder and function from an external file. Problem with importing forms, using and retrieving content - JassWeb","isPartOf":{"@id":"https:\/\/jassweb.com\/solved\/#website"},"datePublished":"2022-12-08T09:02:39+00:00","breadcrumb":{"@id":"https:\/\/jassweb.com\/solved\/solved-print-a-sentence-with-placeholder-and-function-from-an-external-file-problem-with-importing-forms-using-and-retrieving-content\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jassweb.com\/solved\/solved-print-a-sentence-with-placeholder-and-function-from-an-external-file-problem-with-importing-forms-using-and-retrieving-content\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/jassweb.com\/solved\/solved-print-a-sentence-with-placeholder-and-function-from-an-external-file-problem-with-importing-forms-using-and-retrieving-content\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/jassweb.com\/solved\/"},{"@type":"ListItem","position":2,"name":"[Solved] Print a sentence with placeholder and function from an external file. Problem with importing forms, using and retrieving content"}]},{"@type":"WebSite","@id":"https:\/\/jassweb.com\/solved\/#website","url":"https:\/\/jassweb.com\/solved\/","name":"JassWeb","description":"Build High-quality Websites","publisher":{"@id":"https:\/\/jassweb.com\/solved\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/jassweb.com\/solved\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/jassweb.com\/solved\/#organization","name":"Jass Web","url":"https:\/\/jassweb.com\/solved\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/","url":"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png","contentUrl":"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png","width":693,"height":132,"caption":"Jass Web"},"image":{"@id":"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31","name":"Kirat","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/image\/","url":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1775798750","contentUrl":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1775798750","caption":"Kirat"},"sameAs":["http:\/\/jassweb.com"],"url":"https:\/\/jassweb.com\/solved\/author\/jaspritsinghghumangmail-com\/"}]}},"_links":{"self":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts\/25186","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/comments?post=25186"}],"version-history":[{"count":0,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts\/25186\/revisions"}],"wp:attachment":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/media?parent=25186"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/categories?post=25186"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/tags?post=25186"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}