{"id":1060,"date":"2018-10-22T10:13:53","date_gmt":"2018-10-22T10:13:53","guid":{"rendered":"http:\/\/learnlearn.uk\/python\/?page_id=1060"},"modified":"2021-04-29T05:46:23","modified_gmt":"2021-04-29T05:46:23","slug":"ascii-art","status":"publish","type":"page","link":"https:\/\/learnlearn.uk\/python\/ascii-art\/","title":{"rendered":"Adding ASCII art to your Python programs"},"content":{"rendered":"<div class=\"responsive-tabs\">\n<h2 class=\"tabtitle\">Printing ASCII Art<\/h2>\n<div class=\"tabcontent\">\n\n<h3>Printing ASCII Art<\/h3>\n<p>You can print ASCII art that is saved in a separate text file easily. It&#8217;s just 2 lines of code.<\/p>\n<p>Here the program would open the ASCII art saved into a file called bat.txt and print out.<\/p>\n<p><!-- HTML generated using hilite.me --><\/p>\n<div style=\"background: #f0f0f0; overflow: auto; width: auto; border: solid gray; border-width: .1em .1em .1em .8em; padding: .2em .6em;\">\n<pre style=\"margin: 0; line-height: 125%;\">f<span style=\"color: #666666;\">=<\/span> <span style=\"color: #007020;\">open<\/span> (<span style=\"color: #4070a0;\">'bat.txt'<\/span>,<span style=\"color: #4070a0;\">'r'<\/span>)\r\n\r\n<span style=\"color: #007020; font-weight: bold;\">print<\/span>(<span style=\"color: #4070a0;\">''<\/span><span style=\"color: #666666;\">.<\/span>join([line <span style=\"color: #007020; font-weight: bold;\">for<\/span> line <span style=\"color: #007020; font-weight: bold;\">in<\/span> f]))<\/pre>\n<\/div>\n<p>You might want to create a Python procedure to make it even easier to print out lots of different ascii art files if you are using multiple ASCII art files in your program.<\/p>\n<p><!-- HTML generated using hilite.me --><\/p>\n<div style=\"background: #f0f0f0; overflow: auto; width: auto; border: solid gray; border-width: .1em .1em .1em .8em; padding: .2em .6em;\">\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #007020; font-weight: bold;\">def<\/span> <span style=\"color: #06287e;\">print_ascii<\/span>(fn):\r\n    f<span style=\"color: #666666;\">=<\/span> <span style=\"color: #007020;\">open<\/span>(fn,<span style=\"color: #4070a0;\">'r'<\/span>)\r\n    <span style=\"color: #007020; font-weight: bold;\">print<\/span>(<span style=\"color: #4070a0;\">''<\/span><span style=\"color: #666666;\">.<\/span>join([line <span style=\"color: #007020; font-weight: bold;\">for<\/span> line <span style=\"color: #007020; font-weight: bold;\">in<\/span> f]))\r\n\r\nprint_ascii(<span style=\"color: #4070a0;\">'bat.txt'<\/span>)\r\nprint_ascii(<span style=\"color: #4070a0;\">'tree.txt'<\/span>)\r\n<\/pre>\n<\/div>\n<p>You can now use this function anywhere in your code to load ascii art files. If you&#8217;ve saved your files to a subfolder then you will need to <a href=\"https:\/\/stackoverflow.com\/questions\/7165749\/open-file-in-a-relative-location-in-python\">follow the instructions here.<\/a><\/p>\n<p>Warning &#8211; make sure you save your ASCII art in the same folder as your code.<\/p>\n\n<\/div><h2 class=\"tabtitle\">Animated ASCII Art<\/h2>\n<div class=\"tabcontent\">\n\n<h3>Animated ASCII Art Tutorial<\/h3>\n<p>If you want to add animated ASCII art to your programs then you can follow this tutorial here:<\/p>\n<p><a href=\"https:\/\/drive.google.com\/open?id=1VDKji4v1vGd1ihluBi_uXoSIQTizCn6A\">Can&#8217;t access YouTube? Click here for the Google Drive Version<\/a><\/p>\n<p><iframe loading=\"lazy\" src=\"https:\/\/www.youtube.com\/embed\/JavJqJHLo_M\" width=\"860\" height=\"600\" frameborder=\"0\" allowfullscreen=\"allowfullscreen\"><\/iframe><\/p>\n\n<\/div><h2 class=\"tabtitle\">Text to ASCII Art<\/h2>\n<div class=\"tabcontent\">\n\n<h3>Text to ASCII Converter<\/h3>\n<p>In this tutorial we show you how you can convert text to ASCII art in only 2 lines of code \ud83d\ude42<\/p>\n<div class=\"nv-iframe-embed\">\n<div class=\"container-lazyload preview-lazyload container-youtube js-lazyload--not-loaded\"><a href=\"https:\/\/www.youtube.com\/watch?v=U1aUteSg2a4\" class=\"lazy-load-youtube preview-lazyload preview-youtube\" data-video-title=\"Python - Converting text to Big ASCII Text using Pyfiglet\" title=\"Play video &quot;Python - Converting text to Big ASCII Text using Pyfiglet&quot;\">https:\/\/www.youtube.com\/watch?v=U1aUteSg2a4<\/a><noscript>Video can&#8217;t be loaded because JavaScript is disabled: <a href=\"https:\/\/www.youtube.com\/watch?v=U1aUteSg2a4\" title=\"Python - Converting text to Big ASCII Text using Pyfiglet\">Python &#8211; Converting text to Big ASCII Text using Pyfiglet (https:\/\/www.youtube.com\/watch?v=U1aUteSg2a4)<\/a><\/noscript><\/div>\n<\/div>\n\n<\/div><h2 class=\"tabtitle\">Colorful ASCII<\/h2>\n<div class=\"tabcontent\">\n\n<h3>Colorful ASCII Art<\/h3>\n<p>You can change the colors of text within your programs and you can even make your ASCII art multicolor. Watch this video for a full tutorial on how to do it.<\/p>\n<div class=\"nv-iframe-embed\">\n<div class=\"container-lazyload preview-lazyload container-youtube js-lazyload--not-loaded\"><a href=\"https:\/\/youtu.be\/u4QmAIoo4i0\" class=\"lazy-load-youtube preview-lazyload preview-youtube\" data-video-title=\"Python Console Colors - Easy Tutorial\" title=\"Play video &quot;Python Console Colors - Easy Tutorial&quot;\">https:\/\/youtu.be\/u4QmAIoo4i0<\/a><noscript>Video can&#8217;t be loaded because JavaScript is disabled: <a href=\"https:\/\/youtu.be\/u4QmAIoo4i0\" title=\"Python Console Colors - Easy Tutorial\">Python Console Colors &#8211; Easy Tutorial (https:\/\/youtu.be\/u4QmAIoo4i0)<\/a><\/noscript><\/div>\n<\/div>\n<p>&nbsp;<\/p>\n\n<\/div><h2 class=\"tabtitle\">Links<\/h2>\n<div class=\"tabcontent\">\n\n<p><a href=\"http:\/\/patorjk.com\/software\/taag\/#p=display&amp;f=Graffiti&amp;t=Type%20Something%20\">ASCII Text Generator<\/a><\/p>\n<p><a href=\"https:\/\/www.asciiart.eu\/\">ASCII Art<\/a><\/p>\n<p>&nbsp;<\/p>\n<\/div><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Printing ASCII Art You can print ASCII art that is saved in a separate text file easily. It&#8217;s just 2 lines of code. Here the program would open the ASCII art saved into a file called bat.txt and print out. f= open (&#8216;bat.txt&#8217;,&#8217;r&#8217;) print(&#8221;.join([line for line in f])) You might want to create a Python&hellip;&nbsp;<a href=\"https:\/\/learnlearn.uk\/python\/ascii-art\/\" class=\"\" rel=\"bookmark\">Read More &raquo;<span class=\"screen-reader-text\">Adding ASCII art to your Python programs<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"neve_meta_sidebar":"","neve_meta_container":"","neve_meta_enable_content_width":"","neve_meta_content_width":70,"neve_meta_title_alignment":"","neve_meta_author_avatar":"","neve_post_elements_order":"","neve_meta_disable_header":"","neve_meta_disable_footer":"","neve_meta_disable_title":""},"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.6 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Adding ASCII art to your Python programs - Python<\/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:\/\/learnlearn.uk\/python\/ascii-art\/\" \/>\n<meta property=\"og:locale\" content=\"en_GB\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Adding ASCII art to your Python programs - Python\" \/>\n<meta property=\"og:description\" content=\"Printing ASCII Art You can print ASCII art that is saved in a separate text file easily. It&#8217;s just 2 lines of code. Here the program would open the ASCII art saved into a file called bat.txt and print out. f= open (&#039;bat.txt&#039;,&#039;r&#039;) print(&#039;&#039;.join([line for line in f])) You might want to create a Python&hellip;&nbsp;Read More &raquo;Adding ASCII art to your Python programs\" \/>\n<meta property=\"og:url\" content=\"https:\/\/learnlearn.uk\/python\/ascii-art\/\" \/>\n<meta property=\"og:site_name\" content=\"Python\" \/>\n<meta property=\"article:modified_time\" content=\"2021-04-29T05:46:23+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Estimated reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/learnlearn.uk\/python\/ascii-art\/\",\"url\":\"https:\/\/learnlearn.uk\/python\/ascii-art\/\",\"name\":\"Adding ASCII art to your Python programs - Python\",\"isPartOf\":{\"@id\":\"https:\/\/learnlearn.uk\/python\/#website\"},\"datePublished\":\"2018-10-22T10:13:53+00:00\",\"dateModified\":\"2021-04-29T05:46:23+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/learnlearn.uk\/python\/ascii-art\/#breadcrumb\"},\"inLanguage\":\"en-GB\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/learnlearn.uk\/python\/ascii-art\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/learnlearn.uk\/python\/ascii-art\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Python Unit Home\",\"item\":\"https:\/\/learnlearn.uk\/python\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Adding ASCII art to your Python programs\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/learnlearn.uk\/python\/#website\",\"url\":\"https:\/\/learnlearn.uk\/python\/\",\"name\":\"Python\",\"description\":\"Programming\",\"publisher\":{\"@id\":\"https:\/\/learnlearn.uk\/python\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/learnlearn.uk\/python\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-GB\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/learnlearn.uk\/python\/#organization\",\"name\":\"Python\",\"url\":\"https:\/\/learnlearn.uk\/python\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-GB\",\"@id\":\"https:\/\/learnlearn.uk\/python\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/learnlearn.uk\/python\/wp-content\/uploads\/sites\/4\/2019\/03\/LearnLearnLogowhite.png\",\"contentUrl\":\"https:\/\/learnlearn.uk\/python\/wp-content\/uploads\/sites\/4\/2019\/03\/LearnLearnLogowhite.png\",\"width\":710,\"height\":98,\"caption\":\"Python\"},\"image\":{\"@id\":\"https:\/\/learnlearn.uk\/python\/#\/schema\/logo\/image\/\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Adding ASCII art to your Python programs - Python","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:\/\/learnlearn.uk\/python\/ascii-art\/","og_locale":"en_GB","og_type":"article","og_title":"Adding ASCII art to your Python programs - Python","og_description":"Printing ASCII Art You can print ASCII art that is saved in a separate text file easily. It&#8217;s just 2 lines of code. Here the program would open the ASCII art saved into a file called bat.txt and print out. f= open ('bat.txt','r') print(''.join([line for line in f])) You might want to create a Python&hellip;&nbsp;Read More &raquo;Adding ASCII art to your Python programs","og_url":"https:\/\/learnlearn.uk\/python\/ascii-art\/","og_site_name":"Python","article_modified_time":"2021-04-29T05:46:23+00:00","twitter_card":"summary_large_image","twitter_misc":{"Estimated reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/learnlearn.uk\/python\/ascii-art\/","url":"https:\/\/learnlearn.uk\/python\/ascii-art\/","name":"Adding ASCII art to your Python programs - Python","isPartOf":{"@id":"https:\/\/learnlearn.uk\/python\/#website"},"datePublished":"2018-10-22T10:13:53+00:00","dateModified":"2021-04-29T05:46:23+00:00","breadcrumb":{"@id":"https:\/\/learnlearn.uk\/python\/ascii-art\/#breadcrumb"},"inLanguage":"en-GB","potentialAction":[{"@type":"ReadAction","target":["https:\/\/learnlearn.uk\/python\/ascii-art\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/learnlearn.uk\/python\/ascii-art\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Python Unit Home","item":"https:\/\/learnlearn.uk\/python\/"},{"@type":"ListItem","position":2,"name":"Adding ASCII art to your Python programs"}]},{"@type":"WebSite","@id":"https:\/\/learnlearn.uk\/python\/#website","url":"https:\/\/learnlearn.uk\/python\/","name":"Python","description":"Programming","publisher":{"@id":"https:\/\/learnlearn.uk\/python\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/learnlearn.uk\/python\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-GB"},{"@type":"Organization","@id":"https:\/\/learnlearn.uk\/python\/#organization","name":"Python","url":"https:\/\/learnlearn.uk\/python\/","logo":{"@type":"ImageObject","inLanguage":"en-GB","@id":"https:\/\/learnlearn.uk\/python\/#\/schema\/logo\/image\/","url":"https:\/\/learnlearn.uk\/python\/wp-content\/uploads\/sites\/4\/2019\/03\/LearnLearnLogowhite.png","contentUrl":"https:\/\/learnlearn.uk\/python\/wp-content\/uploads\/sites\/4\/2019\/03\/LearnLearnLogowhite.png","width":710,"height":98,"caption":"Python"},"image":{"@id":"https:\/\/learnlearn.uk\/python\/#\/schema\/logo\/image\/"}}]}},"rttpg_featured_image_url":null,"rttpg_author":{"display_name":"learnlearnadmin","author_link":"https:\/\/learnlearn.uk\/python\/author\/learnlearnadmin\/"},"rttpg_comment":0,"rttpg_category":null,"rttpg_excerpt":"Printing ASCII Art You can print ASCII art that is saved in a separate text file easily. It&#8217;s just 2 lines of code. Here the program would open the ASCII art saved into a file called bat.txt and print out. f= open ('bat.txt','r') print(''.join([line for line in f])) You might want to create a Python&hellip;&nbsp;Read&hellip;","_links":{"self":[{"href":"https:\/\/learnlearn.uk\/python\/wp-json\/wp\/v2\/pages\/1060"}],"collection":[{"href":"https:\/\/learnlearn.uk\/python\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/learnlearn.uk\/python\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/learnlearn.uk\/python\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/learnlearn.uk\/python\/wp-json\/wp\/v2\/comments?post=1060"}],"version-history":[{"count":17,"href":"https:\/\/learnlearn.uk\/python\/wp-json\/wp\/v2\/pages\/1060\/revisions"}],"predecessor-version":[{"id":1283,"href":"https:\/\/learnlearn.uk\/python\/wp-json\/wp\/v2\/pages\/1060\/revisions\/1283"}],"wp:attachment":[{"href":"https:\/\/learnlearn.uk\/python\/wp-json\/wp\/v2\/media?parent=1060"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}