<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Pranav Baburaj</title>
    <description>The latest articles on Forem by Pranav Baburaj (@pranavbaburaj).</description>
    <link>https://forem.com/pranavbaburaj</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F556575%2F8bf69697-36b5-413e-9346-c7dee04e5726.jpeg</url>
      <title>Forem: Pranav Baburaj</title>
      <link>https://forem.com/pranavbaburaj</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/pranavbaburaj"/>
    <language>en</language>
    <item>
      <title>Print images to console using Python</title>
      <dc:creator>Pranav Baburaj</dc:creator>
      <pubDate>Wed, 29 Sep 2021 17:40:12 +0000</pubDate>
      <link>https://forem.com/pranavbaburaj/print-images-to-console-using-python-23k6</link>
      <guid>https://forem.com/pranavbaburaj/print-images-to-console-using-python-23k6</guid>
      <description>&lt;p&gt;Hello everyone, hope you all are doing good. I would like to show you how to print images onto the console using Python. So, let's get started.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Before getting started, make sure to have pip and python installed in your system&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Getting started
&lt;/h2&gt;

&lt;p&gt;Install required packages&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

pip &lt;span class="nb"&gt;install &lt;/span&gt;pillow colr


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;Now, you have setup the development environment. Let's get into the code&lt;/p&gt;

&lt;p&gt;First, import the necessary libraries. The script uses the &lt;code&gt;pillow&lt;/code&gt; library for Image processing&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;

&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;PIL&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Image&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;colr&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Colr&lt;/span&gt;

&lt;span class="c1"&gt;# Ask the user for image filename
&lt;/span&gt;&lt;span class="n"&gt;image_path&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;input&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Image:&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;In this example, I am prompting the user to enter the filename for the image and collect it in the &lt;code&gt;image_path&lt;/code&gt; variable.&lt;/p&gt;

&lt;p&gt;Next, open the image &lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;

&lt;span class="n"&gt;image&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Image&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;open&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;image_path&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;Now that we have opened the image. we need to read the image and get the colors. For that, use&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;

&lt;span class="n"&gt;pixel_values&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;image&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getdata&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;blockquote&gt;
&lt;p&gt;The &lt;code&gt;image.getdata()&lt;/code&gt; function returns a list of RGB or RGBA values.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Now, lets print the image&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;

&lt;span class="n"&gt;width&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;height&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;image&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;size&lt;/span&gt;
&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;index&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;character&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="nf"&gt;enumerate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;pixel_values&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="nf"&gt;isinstance&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;character&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;tuple&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;list&lt;/span&gt;&lt;span class="p"&gt;)):&lt;/span&gt;
        &lt;span class="k"&gt;continue&lt;/span&gt;
    &lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;g&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;character&lt;/span&gt;&lt;span class="p"&gt;[:&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;index&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="n"&gt;width&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;""&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Colr&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;rgb&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;g&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\u2584&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="n"&gt;end&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;""&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;Wait, let me explain. &lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;

&lt;span class="n"&gt;width&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;height&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;image&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;size&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;This &lt;code&gt;image.size&lt;/code&gt; property is a tuple containing the width and the height of the image.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;

&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;index&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;character&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="nf"&gt;enumerate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;pixel_values&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="nf"&gt;isinstance&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;character&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;tuple&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;list&lt;/span&gt;&lt;span class="p"&gt;)):&lt;/span&gt;
        &lt;span class="k"&gt;continue&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;We loop through the list of rgb colors and make sure that all the values are either in the form of tuple or list.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;

&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;g&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;character&lt;/span&gt;&lt;span class="p"&gt;[:&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;This line unpacks the tuple into variables for red(&lt;code&gt;r&lt;/code&gt;), green(&lt;code&gt;g&lt;/code&gt;) and blue(&lt;code&gt;b&lt;/code&gt;)&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;

&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Colr&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;rgb&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;g&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\u2584&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="n"&gt;end&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;""&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;This line prints a pixel onto the screen.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.discordapp.com%2Fattachments%2F875983412639436850%2F891594483626573844%2Funknown.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.discordapp.com%2Fattachments%2F875983412639436850%2F891594483626573844%2Funknown.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I have created a python library for printing images onto the console. Check out the GitHub repository &lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev.to%2Fassets%2Fgithub-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/lainq" rel="noopener noreferrer"&gt;
        lainq
      &lt;/a&gt; / &lt;a href="https://github.com/lainq/img" rel="noopener noreferrer"&gt;
        img
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      A python library to display images in the terminal
    &lt;/h3&gt;
  &lt;/div&gt;
  &lt;div class="ltag-github-body"&gt;
    
&lt;div id="readme" class="md"&gt;
&lt;div&gt;
&lt;div class="markdown-heading"&gt;
&lt;h1 class="heading-element"&gt;&lt;b&gt;&lt;code&gt;Img&lt;/code&gt;&lt;/b&gt;&lt;/h1&gt;
&lt;/div&gt;

&lt;p&gt;Display Images in your terminal with python&lt;br&gt;
 &lt;br&gt;&lt;br&gt;
&lt;a rel="noopener noreferrer nofollow" href="https://camo.githubusercontent.com/4e81d80dd4a684f01af8db9f63ae46e1ed0cea561748dc6541dd7153a05abb7c/68747470733a2f2f692e696d6775722e636f6d2f4f317a496763612e706e67"&gt;&lt;img src="https://camo.githubusercontent.com/4e81d80dd4a684f01af8db9f63ae46e1ed0cea561748dc6541dd7153a05abb7c/68747470733a2f2f692e696d6775722e636f6d2f4f317a496763612e706e67" height="150"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;
    &lt;a rel="noopener noreferrer nofollow" href="https://camo.githubusercontent.com/aad97350572e0c87f4338dd2ada663b85e06c3638f04714479c4bdd5b0bc7d6d/68747470733a2f2f7374617469632e706570792e746563682f62616467652f7465726d696e616c2d696d67"&gt;&lt;img src="https://camo.githubusercontent.com/aad97350572e0c87f4338dd2ada663b85e06c3638f04714479c4bdd5b0bc7d6d/68747470733a2f2f7374617469632e706570792e746563682f62616467652f7465726d696e616c2d696d67"&gt;&lt;/a&gt;
    &lt;a rel="noopener noreferrer nofollow" href="https://camo.githubusercontent.com/605dc3db18747f1c2ada7f287677a18d7fc23ce64d97d5c4d054fd469d0f5612/68747470733a2f2f6261646765732e66726170736f66742e636f6d2f6f732f76312f6f70656e2d736f757263652e7376673f763d313033"&gt;&lt;img src="https://camo.githubusercontent.com/605dc3db18747f1c2ada7f287677a18d7fc23ce64d97d5c4d054fd469d0f5612/68747470733a2f2f6261646765732e66726170736f66742e636f6d2f6f732f76312f6f70656e2d736f757263652e7376673f763d313033"&gt;&lt;/a&gt;
    &lt;a rel="noopener noreferrer nofollow" href="https://camo.githubusercontent.com/817a0931571beae29cec302b0542f7c92e540d69ec5d752ffbfa3c8e965f286f/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6173742d636f6d6d69742f7072616e61766261627572616a2f696d67"&gt;&lt;img src="https://camo.githubusercontent.com/817a0931571beae29cec302b0542f7c92e540d69ec5d752ffbfa3c8e965f286f/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6173742d636f6d6d69742f7072616e61766261627572616a2f696d67"&gt;&lt;/a&gt;
    &lt;a href="https://twitter.com/intent/tweet?text=Display%20images%20in%20the%20the%20terminal%20using%20python&amp;amp;url=https://github.com/pranavbaburaj/img&amp;amp;via=_pranavbaburaj&amp;amp;hashtags=developers,images,terminal" rel="nofollow noopener noreferrer"&gt;&lt;img src="https://camo.githubusercontent.com/4f677ce944dfdeb7a8cd741560d35d006363ef6160adeb63ee3d8c73373b1f51/68747470733a2f2f696d672e736869656c64732e696f2f747769747465722f75726c2f687474702f736869656c64732e696f2e7376673f7374796c653d736f6369616c"&gt;&lt;/a&gt;
  &lt;/p&gt;
&lt;/div&gt;
&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;Installation&lt;/h2&gt;
&lt;/div&gt;
&lt;p&gt;The package can be installed via &lt;code&gt;pip&lt;/code&gt;&lt;/p&gt;
&lt;div class="highlight highlight-source-python notranslate position-relative overflow-auto js-code-highlight"&gt;
&lt;pre&gt;&lt;span class="pl-s1"&gt;pip&lt;/span&gt; &lt;span class="pl-s1"&gt;install&lt;/span&gt; &lt;span class="pl-s1"&gt;terminal&lt;/span&gt;&lt;span class="pl-c1"&gt;-&lt;/span&gt;&lt;span class="pl-s1"&gt;img&lt;/span&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;Quick Start&lt;/h2&gt;
&lt;/div&gt;
&lt;p&gt;The library is really simple to get started with. Here's is an example of how you display an image&lt;/p&gt;
&lt;div class="highlight highlight-source-python notranslate position-relative overflow-auto js-code-highlight"&gt;
&lt;pre&gt;&lt;span class="pl-k"&gt;from&lt;/span&gt; &lt;span class="pl-s1"&gt;image&lt;/span&gt; &lt;span class="pl-k"&gt;import&lt;/span&gt; &lt;span class="pl-v"&gt;DrawImage&lt;/span&gt;

&lt;span class="pl-s1"&gt;image&lt;/span&gt; &lt;span class="pl-c1"&gt;=&lt;/span&gt; &lt;span class="pl-v"&gt;DrawImage&lt;/span&gt;.&lt;span class="pl-en"&gt;from_file&lt;/span&gt;(&lt;span class="pl-s"&gt;"image.png"&lt;/span&gt;)
&lt;span class="pl-s1"&gt;image&lt;/span&gt;.&lt;span class="pl-en"&gt;draw_image&lt;/span&gt;()&lt;/pre&gt;

&lt;/div&gt;
&lt;blockquote&gt;
&lt;p&gt;You can also use a url if you dont have the file locally stored&lt;/p&gt;
&lt;/blockquote&gt;
&lt;div class="highlight highlight-source-python notranslate position-relative overflow-auto js-code-highlight"&gt;
&lt;pre&gt;&lt;span class="pl-s1"&gt;image&lt;/span&gt; &lt;span class="pl-c1"&gt;=&lt;/span&gt; &lt;span class="pl-v"&gt;DrawImage&lt;/span&gt;.&lt;span class="pl-en"&gt;from_url&lt;/span&gt;(&lt;span class="pl-s"&gt;"url"&lt;/span&gt;)
&lt;span class="pl-s1"&gt;image&lt;/span&gt;.&lt;span class="pl-en"&gt;draw_image&lt;/span&gt;()&lt;/pre&gt;

&lt;/div&gt;
&lt;blockquote&gt;
&lt;p&gt;The library can also be used with PIL images&lt;/p&gt;
&lt;/blockquote&gt;
&lt;div class="highlight highlight-source-python notranslate position-relative overflow-auto js-code-highlight"&gt;
&lt;pre&gt;&lt;span class="pl-k"&gt;from&lt;/span&gt; &lt;span class="pl-v"&gt;PIL&lt;/span&gt; &lt;span class="pl-k"&gt;import&lt;/span&gt; &lt;span class="pl-v"&gt;Image&lt;/span&gt;
&lt;span class="pl-k"&gt;from&lt;/span&gt; &lt;span class="pl-s1"&gt;image&lt;/span&gt; &lt;span class="pl-k"&gt;import&lt;/span&gt; &lt;span class="pl-v"&gt;DrawImage&lt;/span&gt;

&lt;span class="pl-s1"&gt;img&lt;/span&gt; &lt;span class="pl-c1"&gt;=&lt;/span&gt; &lt;span class="pl-v"&gt;DrawImage&lt;/span&gt;(&lt;span class="pl-v"&gt;Image&lt;/span&gt;.&lt;span class="pl-en"&gt;open&lt;/span&gt;(&lt;span class="pl-s"&gt;"img.png"&lt;/span&gt;))
&lt;span class="pl-s1"&gt;img&lt;/span&gt;.&lt;span class="pl-en"&gt;draw_image&lt;/span&gt;()&lt;/pre&gt;

&lt;/div&gt;
&lt;div class="markdown-heading"&gt;
&lt;h4 class="heading-element"&gt;CLI&lt;/h4&gt;

&lt;/div&gt;
&lt;div class="snippet-clipboard-content notranslate position-relative overflow-auto"&gt;&lt;pre class="notranslate"&gt;&lt;code&gt;img &amp;lt;file or url&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;Methods&lt;/h2&gt;

&lt;/div&gt;
&lt;div class="markdown-heading"&gt;
&lt;h4 class="heading-element"&gt;&lt;code&gt;image.DrawImage&lt;/code&gt;&lt;/h4&gt;

&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;image&lt;/code&gt;: The PIL image&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;size&lt;/code&gt;(&lt;em&gt;&lt;code&gt;Optional[Tuple]&lt;/code&gt;&lt;/em&gt;) : The size of the image to be displayed. Default: 24, 24&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="markdown-heading"&gt;
&lt;h4 class="heading-element"&gt;&lt;code&gt;image.DrawImage.from_file&lt;/code&gt;&lt;/h4&gt;

&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;filename&lt;/code&gt;: The name of the…&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="gh-btn-container"&gt;&lt;a class="gh-btn" href="https://github.com/lainq/img" rel="noopener noreferrer"&gt;View on GitHub&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;


&lt;p&gt;Please let me know what you thing. Hope you learned something new today. Thank you for reading :)&lt;/p&gt;

</description>
      <category>python</category>
      <category>images</category>
      <category>console</category>
      <category>terminal</category>
    </item>
    <item>
      <title>Introducing to you - Polyglot</title>
      <dc:creator>Pranav Baburaj</dc:creator>
      <pubDate>Tue, 13 Apr 2021 12:19:27 +0000</pubDate>
      <link>https://forem.com/pranavbaburaj/introducing-to-you-polyglot-22g1</link>
      <guid>https://forem.com/pranavbaburaj/introducing-to-you-polyglot-22g1</guid>
      <description>&lt;p&gt;I've recently been working on a side project called &lt;code&gt;polyglot&lt;/code&gt;. Polyglot is a python module that finds the percentage of different programming languages used in your project.&lt;/p&gt;


&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev.to%2Fassets%2Fgithub-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/lainq" rel="noopener noreferrer"&gt;
        lainq
      &lt;/a&gt; / &lt;a href="https://github.com/lainq/polyglot" rel="noopener noreferrer"&gt;
        polyglot
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      Find the percentage of programming languages used in your project
    &lt;/h3&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;br&gt;
You can check it out on Github and also drop a star.
&lt;h2&gt;
  
  
  Get Started
&lt;/h2&gt;

&lt;p&gt;In order to get started, you will need to have python and pip installed on your system.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Check the versions of &lt;code&gt;python&lt;/code&gt; and &lt;code&gt;pip&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;python -v
pip -v
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;Install &lt;code&gt;python-polyglot&lt;/code&gt; using &lt;code&gt;pip&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To install &lt;code&gt;python-polyglot&lt;/code&gt; in your system, use&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pip install python-polyglot
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  How to use it
&lt;/h2&gt;

&lt;p&gt;Once Polyglot is all set up and good to go, implementing is easy as pie.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;polyglot.core&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Polyglot&lt;/span&gt;

&lt;span class="c1"&gt;# dot(.) represents the current working directory
&lt;/span&gt;&lt;span class="n"&gt;dirname&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;.&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt; &lt;span class="ow"&gt;or&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;path/to/dir&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;

&lt;span class="n"&gt;poly&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Polyglot&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;.&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;poly&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;show&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This prints out something similar&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;+-------------------------+-------+
|         Language        | files |
+-------------------------+-------+
|       Ignore List       |  5.88 |
| GCC Machine Description | 11.76 |
|          Unknown        |  5.88 |
|           Text          |  5.88 |
|          Python         | 64.71 |
|           JSON          |  5.88 |
+-------------------------+-------+


+-------------------------+-------+
|         Language        | lines |
+-------------------------+-------+
|       Ignore List       | 17.22 |
| GCC Machine Description | 22.24 |
|         Unknown         |  2.83 |
|           Text          |  0.26 |
|          Python         | 57.07 |
|           JSON          |  0.39 |
+-------------------------+-------+
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;code&gt;Ignores&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;ignore&lt;/code&gt; option is used to ignore specific files in the directory tree. For instance, if you don't want the &lt;code&gt;JSON&lt;/code&gt; files to appear in the table, you can add the &lt;code&gt;.json&lt;/code&gt; extension to a &lt;code&gt;polyglot-ignore&lt;/code&gt; file and pass it as a parameter while creating the polyglot instance.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;Polyglot Ignores&lt;/code&gt;&lt;br&gt;
Polyglot ignores are used to ignore &lt;br&gt;
specific files in the directory tree. They &lt;br&gt;
should have a &lt;code&gt;.polyglot&lt;/code&gt; file extension.&lt;br&gt;
Polyglot Ignores as similar to gitignores &lt;br&gt;
and are easy to write with almost the same &lt;br&gt;
syntax. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;Writing a Polyglot ignore.&lt;/code&gt;&lt;br&gt;
Create a &lt;code&gt;test.polyglot&lt;/code&gt; file and add the &lt;br&gt;
files to ignore&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="c1"&gt;# for a specific file extension&lt;/span&gt;
&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;

&lt;span class="c1"&gt;# for a specific folder&lt;/span&gt;
&lt;span class="n"&gt;dist&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;

&lt;span class="c1"&gt;# for a specific file&lt;/span&gt;
&lt;span class="n"&gt;dub&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sdl&lt;/span&gt;
&lt;span class="no"&gt;LICENSE&lt;/span&gt;

&lt;span class="c1"&gt;# for specific folders in the directory&lt;/span&gt;
&lt;span class="o"&gt;~&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;tox&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once you have an ignore file, use it with polyglot like this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;poly&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Polyglot&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;dirname&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ignore&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;test.polyglot&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;code&gt;Arguments&lt;/code&gt;
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;polyglot.arugments&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Arguments&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The Polyglot Arguments is used to parse a list of arguments(&lt;code&gt;sys.argv[1:]&lt;/code&gt; by default) and perform actions related to Polyglot. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You can either pass in arguments manually
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;args&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Arguments&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;arguments&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;
&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;--show=True&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;--dir=.&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;--o=out.json&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;--ignore=test.polyglot&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="n"&gt;return_value&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;False&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;or leave it blank to parse the command line arguments passed in along with the file&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;args&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Arguments&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Start the argument parser
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;parse&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The command-line parser has four main options,&lt;br&gt;
&lt;code&gt;--dir&lt;/code&gt;(default:&lt;code&gt;current directory&lt;/code&gt;) - The directory path&lt;br&gt;
&lt;code&gt;--show&lt;/code&gt;(default:&lt;code&gt;True&lt;/code&gt;) - Whether to display the table or not&lt;br&gt;
&lt;code&gt;--o&lt;/code&gt;(default:&lt;code&gt;None&lt;/code&gt;) - Outputs the data as JSON in the file&lt;br&gt;
&lt;code&gt;--ignore&lt;/code&gt;(default:&lt;code&gt;None&lt;/code&gt;) - The ignore file&lt;/p&gt;

&lt;p&gt;An example usage&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;python -B &amp;lt;filename&amp;gt;.py --dir=. --show=False
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;Please star the project on GitHub if you like it. And thank you for scrolling.&lt;/p&gt;

</description>
      <category>polyglot</category>
      <category>programming</category>
      <category>python</category>
      <category>languages</category>
    </item>
    <item>
      <title>Long - An esoteric language</title>
      <dc:creator>Pranav Baburaj</dc:creator>
      <pubDate>Mon, 29 Mar 2021 08:06:37 +0000</pubDate>
      <link>https://forem.com/pranavbaburaj/long-an-esoteric-language-pag</link>
      <guid>https://forem.com/pranavbaburaj/long-an-esoteric-language-pag</guid>
      <description>&lt;p&gt;Have you ever thought of creating a programming language just for fun? Yes, I made an attempt to create my own Esoteric Programming Language based on ASCII characters.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is an esoteric language?
&lt;/h2&gt;

&lt;p&gt;Esoteric programming languages are weird languages created just for fun rather than for practical use.&lt;/p&gt;

&lt;p&gt;Some examples include Befunge&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; "dlroW olleH"&amp;gt;:v
              ^,_@
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;LOLCODE&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;HAI
CAN HAS STDIO?
VISIBLE "HAI WORLD!"
KTHXBYE
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and Shakespeare&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Act I: Hamlet's insults and flattery.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;h2&gt;
  
  
  Long
&lt;/h2&gt;

&lt;p&gt;Long is a simple,  useless, minimal esoteric programming language created for fun. The language is based on &lt;code&gt;ASCII&lt;/code&gt; characters. You can find the code in &lt;a href="https://github.com/pranavbaburaj/long"&gt;GitHub&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight brainfuck"&gt;&lt;code&gt;&lt;span class="c1"&gt;72&lt;/span&gt;&lt;span class="nf"&gt;+&lt;/span&gt;&lt;span class="c1"&gt;#29&lt;/span&gt;&lt;span class="nf"&gt;+&lt;/span&gt;&lt;span class="c1"&gt;#7&lt;/span&gt;&lt;span class="nf"&gt;+&lt;/span&gt;&lt;span class="c1"&gt;##3&lt;/span&gt;&lt;span class="nf"&gt;+&lt;/span&gt;&lt;span class="c1"&gt;#79&lt;/span&gt;&lt;span class="nf"&gt;-&lt;/span&gt;&lt;span class="c1"&gt;# 55&lt;/span&gt;&lt;span class="nf"&gt;+&lt;/span&gt;&lt;span class="c1"&gt;#24&lt;/span&gt;&lt;span class="nf"&gt;+&lt;/span&gt;&lt;span class="c1"&gt;#3&lt;/span&gt;&lt;span class="nf"&gt;+&lt;/span&gt;&lt;span class="c1"&gt;#6&lt;/span&gt;&lt;span class="nf"&gt;-&lt;/span&gt;&lt;span class="c1"&gt;#8&lt;/span&gt;&lt;span class="nf"&gt;-&lt;/span&gt;&lt;span class="c1"&gt;#68&lt;/span&gt;&lt;span class="nf"&gt;-&lt;/span&gt;&lt;span class="c1"&gt;#1&lt;/span&gt;&lt;span class="nf"&gt;+&lt;/span&gt;&lt;span class="c1"&gt;# ;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;h2&gt;
  
  
  How long works ??
&lt;/h2&gt;

&lt;p&gt;The long programming language works like this:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Takes the file to run&lt;/li&gt;
&lt;li&gt;The lexer breaks down the code into specific tokens and store them in an array&lt;/li&gt;
&lt;li&gt;The tokens are grouped into different commands.&lt;/li&gt;
&lt;li&gt;The commands are executed &lt;/li&gt;
&lt;/ul&gt;



&lt;h2&gt;
  
  
  How to use it??
&lt;/h2&gt;

&lt;p&gt;Using long is pretty simple. You just have to create a project and run it.&lt;/p&gt;

&lt;p&gt;To create a project, run&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;long new
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and answer all the prompts and you are ready to go. To run the project, get into the project directory and run &lt;code&gt;long run&lt;/code&gt;(Make sure you have the right file mentioned in the &lt;code&gt;entry-point&lt;/code&gt; field in the &lt;code&gt;long.json&lt;/code&gt; file). Or, you can directly mention the file name like this,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;long &amp;lt;path-to-file&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The language works based on the value which is incremented and decremented&lt;/p&gt;

&lt;p&gt;The main commands in the language are the following,&lt;br&gt;
&lt;code&gt;#&lt;/code&gt; for printing the current character&lt;br&gt;
&lt;code&gt;!&lt;/code&gt; for setting the value to 0&lt;br&gt;
&lt;code&gt;+&lt;/code&gt;, &lt;code&gt;-&lt;/code&gt;, &lt;code&gt;*&lt;/code&gt;, &lt;code&gt;/&lt;/code&gt; for arithmetic operations&lt;/p&gt;

&lt;p&gt;Arithmetic operations can be performed on the value which is initially set to 0. You can print out the current value converted to a character with the print command(&lt;code&gt;#&lt;/code&gt;).&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight brainfuck"&gt;&lt;code&gt;&lt;span class="c1"&gt;72&lt;/span&gt;&lt;span class="nf"&gt;+&lt;/span&gt;&lt;span class="c1"&gt;# 33&lt;/span&gt;&lt;span class="nf"&gt;+&lt;/span&gt;&lt;span class="c1"&gt;# ;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Result:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Hi
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This piece of code will increase the value by 72 and print the value out. Again, the value is incremented by 33 and printed out.&lt;/p&gt;



&lt;h3&gt;
  
  
  Feel free to contribute on &lt;a href="https://github.com/pranavbaburaj/long"&gt;GitHub&lt;/a&gt;
&lt;/h3&gt;




&lt;p&gt;To reach me just ping me on &lt;a href="https://discord.com/users/763820556491161650"&gt;Discord&lt;/a&gt; and also, don't forget to join my &lt;a href="https://discord.gg/vzcNRVrHR5"&gt;Discord server&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Hope you got something new today. Thank you for scrolling and have a nice day.&lt;/p&gt;

</description>
      <category>language</category>
      <category>project</category>
      <category>esoteric</category>
    </item>
    <item>
      <title>Introducing Hascal - Part 1</title>
      <dc:creator>Pranav Baburaj</dc:creator>
      <pubDate>Sat, 06 Mar 2021 05:56:48 +0000</pubDate>
      <link>https://forem.com/pranavbaburaj/introducing-hascal-part-1-5h1f</link>
      <guid>https://forem.com/pranavbaburaj/introducing-hascal-part-1-5h1f</guid>
      <description>&lt;h2&gt;
  
  
  The Hascal Programming language
&lt;/h2&gt;

&lt;p&gt;Hascal is a small, programming language written in python. It has a C-like syntax, is Fast and Powerful, and it also supports garbage collection&lt;/p&gt;

&lt;p&gt;See the official repository &lt;a href="https://github.com/hascal/hascal"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Hascal is still under development&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Installation and setup
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;Note: As of March 5, 2021, Hascal is only supported for windows, but you can clone the repository and run it&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;To setup Hascal on your windows machine,&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Clone the &lt;a href="https://github.com/hascal/hascal/archive/main.zip"&gt;Hascal repository&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;git clone https://github.com/hascal/hascal.git&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Now, get into the &lt;code&gt;hascal&lt;/code&gt; folder and you can find a &lt;code&gt;build.bat&lt;/code&gt; file. Run the file and you have the hascal executable inside of the dist folder.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Environment variables

&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;a href="https://www.computerhope.com/issues/ch000549.htm"&gt;This&lt;/a&gt; article explains how to manage environment variables in windows&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;PATH&lt;/code&gt; variable
&lt;/h3&gt;

&lt;p&gt;Copy the location of the dist folder and add it into the &lt;code&gt;PATH&lt;/code&gt; variable.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;HPATH&lt;/code&gt; variable
&lt;/h3&gt;

&lt;p&gt;Copy the location of the &lt;code&gt;hascal/src/hlib&lt;/code&gt; folder, create a new environment variable named &lt;code&gt;HPATH&lt;/code&gt; and assign it the value of the copied location&lt;/p&gt;




&lt;p&gt;Let's dive deep into the language in the upcoming articles&lt;/p&gt;

&lt;p&gt;Hope you learned something new, Thank you for reading&lt;/p&gt;

</description>
      <category>hascal</category>
      <category>languages</category>
    </item>
    <item>
      <title>A JSON based database for python</title>
      <dc:creator>Pranav Baburaj</dc:creator>
      <pubDate>Thu, 11 Feb 2021 15:34:29 +0000</pubDate>
      <link>https://forem.com/pranavbaburaj/a-json-based-database-for-python-2hco</link>
      <guid>https://forem.com/pranavbaburaj/a-json-based-database-for-python-2hco</guid>
      <description>&lt;p&gt;In this tutorial, we will check out a database library in python, called &lt;a href="https://github.com/pranavbaburaj/lol"&gt;lol-db&lt;/a&gt;. Before starting this tutorial, I assume that you have a basic knowledge of python and pip. In this tutorial, we will be covering:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Setting up the project&lt;/li&gt;
&lt;li&gt;Creating a database model&lt;/li&gt;
&lt;li&gt;Other database methods&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So, let's get started&lt;/p&gt;

&lt;h1&gt;
  
  
  Project Setup
&lt;/h1&gt;

&lt;p&gt;First of all, we have to set up a python project.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Create a virtual environment and activate it&lt;br&gt;
  Create a virtual environment &lt;br&gt;
 &lt;code&gt;virtualenv env&lt;/code&gt;&lt;br&gt;
 Activate the virtual environment&lt;br&gt;
 &lt;code&gt;source env/bin/activate&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Install lol-db 
Install lol-db using pip
&lt;code&gt;pip install loldb&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Create a python file
&lt;code&gt;touch main.py&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Introducing lol-DB
&lt;/h1&gt;

&lt;p&gt;lol-DB is a python utility library that mainly contains a database and several data types. In this tutorial, we will be going through the database&lt;/p&gt;

&lt;p&gt;To use the lol-DB module, you will have to import it into your python file&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="nn"&gt;lol.database&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;database&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;serializer&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The lol database has two main parts:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The database&lt;/li&gt;
&lt;li&gt;The serializer&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To create a new database model, you can add this code to your file&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt; &lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="nn"&gt;lol.database&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;database&lt;/span&gt;

 &lt;span class="c1"&gt;# Create a model
&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;database&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Database&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"database name"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"age"&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;Database&lt;/code&gt; class takes two main arguments,&lt;br&gt;
 the name of the database(&lt;code&gt;str&lt;/code&gt;) and an array of fields(&lt;code&gt;list of str&lt;/code&gt;).&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;By default the database will create a log message every time you perform an action. To stop this, add the following lines to your code &lt;/p&gt;


&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# set track modifications
&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;set_track_modification&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="bp"&gt;False&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/blockquote&gt;
&lt;h3&gt;
  
  
  Add an item to the database
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;add&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="s"&gt;"Pranav Baburaj"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;13&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;The &lt;code&gt;database.add()&lt;/code&gt; function takes one argument&lt;br&gt;
 which is the list of fields&lt;/p&gt;
&lt;h3&gt;
  
  
  Delete an item from the database
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# to get keys from the database
&lt;/span&gt;&lt;span class="n"&gt;keys&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ids&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

&lt;span class="c1"&gt;# delete the last item from the database
&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;delete&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;keys&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;The &lt;code&gt;delete&lt;/code&gt; function takes a single argument which is the id of the item. You can obtain all the keys by adding this to your code&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ids&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Change an item from the database
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;change&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ids&lt;/span&gt;&lt;span class="p"&gt;()[&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="c1"&gt;# the object id
&lt;/span&gt;    &lt;span class="s"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;# the field name,
&lt;/span&gt;    &lt;span class="s"&gt;"P Pranav Baburaj"&lt;/span&gt; &lt;span class="c1"&gt;# the new value
&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Filter out elements from the database
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;database&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="s"&gt;"age"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;13&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# returns you the object id 
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;filter&lt;/code&gt; function takes a single argument, which is a dict of items to match with the database fields. The function will return a list of object ids&lt;/p&gt;

&lt;h3&gt;
  
  
  Get information from the database
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# pass in the object id
&lt;/span&gt;&lt;span class="n"&gt;database&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;object_id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Clear the database
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;database&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;clear&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;h2&gt;
  
  
  Serializers
&lt;/h2&gt;

&lt;p&gt;If you are using this module along with a web framework, you may have to convert the model into either JSON format or XML. To do this you can use the &lt;code&gt;database.serializer&lt;/code&gt; module&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="nn"&gt;lol.database&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;database&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;serialize&lt;/span&gt;

&lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;database&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Database&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"database name"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"age"&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;

&lt;span class="c1"&gt;# converting to json
&lt;/span&gt;&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;jsonify&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;

&lt;span class="c1"&gt;# converting to XML
&lt;/span&gt;&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;xml&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I hope you were able to learn something new from this blog, &lt;/p&gt;

&lt;p&gt;Star this repository on &lt;a href="https://github.com/pranavbaburaj/lol"&gt;GitHub&lt;/a&gt;&lt;/p&gt;

</description>
      <category>database</category>
      <category>python</category>
      <category>json</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
