<?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: natamacm</title>
    <description>The latest articles on Forem by natamacm (@natamacm).</description>
    <link>https://forem.com/natamacm</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%2F359047%2Fecc29d0e-9cfe-4d00-ad0b-d9d9d0daec89.png</url>
      <title>Forem: natamacm</title>
      <link>https://forem.com/natamacm</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/natamacm"/>
    <language>en</language>
    <item>
      <title>Time Module with Example in Python</title>
      <dc:creator>natamacm</dc:creator>
      <pubDate>Tue, 09 Jun 2020 14:51:58 +0000</pubDate>
      <link>https://forem.com/natamacm/time-module-with-example-in-python-11f0</link>
      <guid>https://forem.com/natamacm/time-module-with-example-in-python-11f0</guid>
      <description>&lt;p&gt;The time module with its functions and examples in the &lt;a href="https://python.org"&gt;Python programming language&lt;/a&gt;.  &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Python time Module&lt;/strong&gt;&lt;br&gt;
The &lt;a href="https://docs.python.org/3/library/time.html"&gt;time module&lt;/a&gt; is an integrated module in Python that has several features for time. For example, you can get the &lt;a href="https://python-commandments.org/current-date-and-time-in-python/"&gt;current date and time&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;To use the time module, you have to import the &lt;strong&gt;time module&lt;/strong&gt; (Python has many &lt;a href="https://pythonbasics.org/modules/"&gt;modules&lt;/a&gt; that let you build your program).&lt;/p&gt;

&lt;p&gt;This module starts the time from the time of the recording. Epoch is history, beginning 1 January 1970. Epoch is history. &lt;/p&gt;
&lt;h2&gt;
  
  
  time()
&lt;/h2&gt;

&lt;p&gt;The epoch time is returned by this function. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Python Example:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight python"&gt;&lt;code&gt;    &lt;span class="c1"&gt;# Import time module
&lt;/span&gt;    &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;time&lt;/span&gt;

    &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'Total seconds since epoch:'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The program above outputs this:    &lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Total seconds since epoch: 1576083939.5877264
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;This works in both the &lt;a href="https://bsdnerds.org/learn-python/"&gt;shell&lt;/a&gt; and in a &lt;a href="https://pythonprogramminglanguage.com/how-to-run/"&gt;script&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  ctime()
&lt;/h2&gt;

&lt;p&gt;This Python function of the time module takes second as an argument and return time until the mentioned seconds.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Python Example:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight python"&gt;&lt;code&gt;    &lt;span class="c1"&gt;# Import time module
&lt;/span&gt;    &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;time&lt;/span&gt;

    &lt;span class="n"&gt;st&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mf"&gt;1575293263.821704&lt;/span&gt;
    &lt;span class="n"&gt;current_time&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ctime&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;st&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'time since epoch:'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;current_time&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The program above outputs this:    &lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;time since epoch: Mon Dec  2 14:27:43 2019
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h2&gt;
  
  
  sleep()
&lt;/h2&gt;

&lt;p&gt;This function is used to pause the execution of the program for the time specified in the arguments. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Python Example:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre class="highlight python"&gt;&lt;code&gt;    &lt;span class="c1"&gt;# Import time module
&lt;/span&gt;    &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;time&lt;/span&gt;

    &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'Execution start time:'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ctime&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
    &lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sleep&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'End execution time:'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ctime&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The program above outputs this:    &lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Execution start time: Tue Jun  9 16:40:56 2020
End execution time: Tue Jun  9 16:41:01 2020
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h2&gt;
  
  
  strftime()
&lt;/h2&gt;

&lt;p&gt;The strftime() function takes an argument and returns a string.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Python Example:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre class="highlight python"&gt;&lt;code&gt;    &lt;span class="c1"&gt;# Import time module
&lt;/span&gt;    &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;time&lt;/span&gt;

    &lt;span class="n"&gt;now_time&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;localtime&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; 

    &lt;span class="n"&gt;tif&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;strftime&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"%m/%d/%Y, %H:%M:%S"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;now_time&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'The time since epoch:'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;tif&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The program above outputs this:    &lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;The time since epoch: 06/09/2020, 16:42:25
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h3&gt;
  
  
  asctime()
&lt;/h3&gt;

&lt;p&gt;The asctime() function takes a tuple of length nine as an argument and returns a &lt;a href="https://pythonspot.com/python-strings/"&gt;string&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Python Example:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre class="highlight python"&gt;&lt;code&gt;    &lt;span class="c1"&gt;# Import time module
&lt;/span&gt;    &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;time&lt;/span&gt;

    &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2020&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;365&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;asctime&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Time and date is:"&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;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The program above outputs this:    &lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Time and date is: Sat Mar  5 02:20:01 2020
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

</description>
      <category>python</category>
    </item>
    <item>
      <title>yield keyword with example</title>
      <dc:creator>natamacm</dc:creator>
      <pubDate>Tue, 09 Jun 2020 14:29:53 +0000</pubDate>
      <link>https://forem.com/natamacm/yield-keyword-with-example-5dnf</link>
      <guid>https://forem.com/natamacm/yield-keyword-with-example-5dnf</guid>
      <description>&lt;p&gt;The Python keyword &lt;strong&gt;yield&lt;/strong&gt; is a keyword in the python, is similar to return, both are in used in a &lt;a href="https://pythonspot.com/functions/"&gt;function&lt;/a&gt; and yield returns values.&lt;/p&gt;

&lt;p&gt;In this article we'll go over several examples of the yield keyword.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Syntax of yield keyword&lt;/strong&gt;&lt;br&gt;
The syntax of the yield keyword is&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight python"&gt;&lt;code&gt;        &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;function&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
            &lt;span class="n"&gt;statements&lt;/span&gt;
            &lt;span class="k"&gt;yield&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt;
            &lt;span class="n"&gt;statements&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Python Example of yield:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight python"&gt;&lt;code&gt;        &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;sampleGenerate&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
            &lt;span class="k"&gt;yield&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;
            &lt;span class="k"&gt;yield&lt;/span&gt; &lt;span class="mi"&gt;200&lt;/span&gt;
            &lt;span class="k"&gt;yield&lt;/span&gt; &lt;span class="mi"&gt;300&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The yield keyword can be used both in the &lt;a href="https://bsdnerds.org/learn-python/"&gt;shell&lt;/a&gt; and from a &lt;a href="https://pythonprogramminglanguage.com/how-to-run/"&gt;script&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  yield examples
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Example 1:&lt;/strong&gt; &lt;br&gt;
Demonstrate the example with yield keywords by returning values multiple times on &lt;a href="https://pythonbasics.org/functions/"&gt;function&lt;/a&gt; calls.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight python"&gt;&lt;code&gt;    &lt;span class="c1"&gt;# python example of yield keyword
&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;sample&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
        &lt;span class="k"&gt;yield&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;
        &lt;span class="k"&gt;yield&lt;/span&gt; &lt;span class="mi"&gt;200&lt;/span&gt;
        &lt;span class="k"&gt;yield&lt;/span&gt; &lt;span class="mi"&gt;300&lt;/span&gt;

    &lt;span class="c1"&gt;# main code
&lt;/span&gt;    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;sample&lt;/span&gt;&lt;span class="p"&gt;():&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;value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The program above outputs this:    &lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;100
200
300
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Example 2:&lt;/strong&gt; &lt;br&gt;
Find the squares of the numbers untill a maximum value. This can be done for various &lt;a href="https://python-commandments.org/python-data-types/"&gt;data types&lt;/a&gt; like integers or floats.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight python"&gt;&lt;code&gt;    &lt;span class="c1"&gt;# python yield keyword    
&lt;/span&gt;    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;square&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
        &lt;span class="n"&gt;c&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
        &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;yield&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;
            &lt;span class="n"&gt;c&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;  

    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;square&lt;/span&gt;&lt;span class="p"&gt;():&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;i&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;i&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;=&lt;/span&gt;&lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;break&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The program above outputs this:    &lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1 
4 
9 
16
25
36
49
64
81
100
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

</description>
      <category>python</category>
    </item>
    <item>
      <title>timeit() Function with Example in Python</title>
      <dc:creator>natamacm</dc:creator>
      <pubDate>Tue, 09 Jun 2020 14:08:04 +0000</pubDate>
      <link>https://forem.com/natamacm/timeit-function-with-example-in-python-4ga8</link>
      <guid>https://forem.com/natamacm/timeit-function-with-example-in-python-4ga8</guid>
      <description>&lt;p&gt;You will learn about the &lt;a href="https://python.org" rel="noopener noreferrer"&gt;Python&lt;/a&gt; timeit() function and shown an example in this tutorial. You can use it to calculate the time of code execution. &lt;/p&gt;

&lt;p&gt;If you run any code, our code execution takes place with a number of background operations. When time() &lt;a href="https://pythonprogramminglanguage.com/functions/" rel="noopener noreferrer"&gt;function&lt;/a&gt; counts on the time it does not take into consideration background operations going on to execute this code. &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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fleojpq115594m4kzmvsx.gif" 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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fleojpq115594m4kzmvsx.gif" alt="time it"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It subtracts time to get the necessary time at beginning and at the end. &lt;strong&gt;timeit() function&lt;/strong&gt; has been developed to define the exact timing of each execution of the code.&lt;/p&gt;

&lt;p&gt;This works both in the Python &lt;a href="https://bsdnerds.org/learn-python/" rel="noopener noreferrer"&gt;shell&lt;/a&gt; and from a &lt;a href="https://pythonbasics.org/execute-python-scripts/" rel="noopener noreferrer"&gt;script&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  timeit() example
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;Code execution time with timeit() function as an example:&lt;/em&gt;&lt;br&gt;
We're going to type and hit python. It reacts with the python version you are using and it also confirms that you work in python. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Import statement:&lt;/strong&gt;    &lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    import timeit
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;Note we're not using the &lt;a href="https://python-commandments.org/current-date-and-time-in-python/" rel="noopener noreferrer"&gt;time module&lt;/a&gt; but &lt;em&gt;timeit&lt;/em&gt; module.&lt;/p&gt;

&lt;p&gt;If you will get a response like 'import' is not defined then go and check for system variable has been updated or not.&lt;/p&gt;

&lt;p&gt;The program does a simple mathematical operation and find its execution timing by two methods.&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="c1"&gt;# python example of timeit() function
&lt;/span&gt;
&lt;span class="c1"&gt;# load module
&lt;/span&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;timeit&lt;/span&gt;

&lt;span class="c1"&gt;# time calcuation
&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="s"&gt;x&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="mi"&gt;5&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="s"&gt;x&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;x&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;x&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;x&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;x&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="n"&gt;timeit&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;timeit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;y = &lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;x&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt; *3&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;number&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10000000&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The program above outputs this:&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;Here you can put the value of number any number times as number times codeexecution required.&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;import&lt;/span&gt; &lt;span class="n"&gt;timeit&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;timeit&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;timeit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;xy = &lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;x&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="s"&gt;x&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="s"&gt;x&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="s"&gt;x&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="s"&gt;x&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;number&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;10000000&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The program above outputs this:    &lt;/p&gt;

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

&lt;/div&gt;

&lt;p&gt;This method describes the method to find execution timing manually. If you want to check an operation many times, instead of &lt;a href="https://pythonspot.com/loops/" rel="noopener noreferrer"&gt;a loop&lt;/a&gt; you can use the method below.&lt;/p&gt;

&lt;h2&gt;
  
  
  timeit example
&lt;/h2&gt;

&lt;p&gt;Now you will see how to perform the same tedious operation automatically?&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;import&lt;/span&gt; &lt;span class="n"&gt;timeit&lt;/span&gt;

&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;timeit&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;repeat&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;y = &lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;x&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;* 3&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;number&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10000000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;repeat&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;5&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="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;timeit&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;repeat&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;xy = &lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;x&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="s"&gt;x&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="s"&gt;x&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="s"&gt;x&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="s"&gt;x&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;number&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10000000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;repeat&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The program above outputs this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[0.13703188695944846, 0.13094416703097522, 0.13312444603070617, 0.14463001501280814, 0.13111430197022855]

[0.1333333159564063, 0.1297284740721807, 0.12939571705646813, 0.1272417320869863, 0.12798011908307672]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here you can see repetitions happen a number of times automatically.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why timeit()?
&lt;/h2&gt;

&lt;p&gt;Because of its precision, the timeit() function is the best way of finding time execution than time.&lt;/p&gt;

&lt;p&gt;Many of our assumptions with regard to execution of the code in timeit() function were incorrect and have been rectified in the &lt;strong&gt;timeit() function&lt;/strong&gt; as well.&lt;/p&gt;

&lt;p&gt;If you are new to Python, I recommend &lt;a href="https://gumroad.com/l/dcsp" rel="noopener noreferrer"&gt;this Python course&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>python</category>
    </item>
    <item>
      <title>What does the 'b' character do in front of a string literal in Python?</title>
      <dc:creator>natamacm</dc:creator>
      <pubDate>Tue, 09 Jun 2020 13:39:37 +0000</pubDate>
      <link>https://forem.com/natamacm/what-does-the-b-character-do-in-front-of-a-string-literal-in-python-2m21</link>
      <guid>https://forem.com/natamacm/what-does-the-b-character-do-in-front-of-a-string-literal-in-python-2m21</guid>
      <description>&lt;p&gt;Python sometimes has the 'b' character in front of a string. You are going to learn how to make a variable type as byte.&lt;/p&gt;

&lt;p&gt;You will also learn &lt;strong&gt;what the 'b' character does in Python&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Example
&lt;/h2&gt;

&lt;p&gt;Consider the following examples,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight python"&gt;&lt;code&gt;    &lt;span class="c1"&gt;# variable definitions
&lt;/span&gt;    &lt;span class="n"&gt;t_str&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;'string'&lt;/span&gt;
    &lt;span class="n"&gt;t_bytes&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;b'string'&lt;/span&gt;

    &lt;span class="c1"&gt;# print the types
&lt;/span&gt;    &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;type&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t_str&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
    &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;type&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t_bytes&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;You can try this both in the &lt;a href="https://bsdnerds.org/learn-python/"&gt;shell&lt;/a&gt; and from a &lt;a href="https://pythonprogramminglanguage.com/how-to-run/"&gt;script&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The program above outputs this:    &lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;class 'str'&amp;gt;
&amp;lt;class 'bytes'&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;This means they are of a different type.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--iKSU9mEj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/ie0mxypdc2e6h4nuc1de.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--iKSU9mEj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/ie0mxypdc2e6h4nuc1de.png" alt="data types"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  String vs bytes
&lt;/h2&gt;

&lt;p&gt;As per the above example, the prefix of 'b' character to a &lt;a href="https://pythonbasics.org/strings/"&gt;string&lt;/a&gt;, makes the variable of &lt;a href="https://python-commandments.org/python-data-types/"&gt;data type&lt;/a&gt; bytes.&lt;/p&gt;

&lt;p&gt;In the prefix 'b' before version 3, python ignored the variable bytes with 'b' in the later version. It can contain ASCII characters and it should be expressed bytes with an escape value of 128 or higher. &lt;/p&gt;

&lt;p&gt;The bytes are the actual data. Strings are an abstraction. A byte is a collection of 8 bits, also known as &lt;a href="https://pythonspot.com/binary-numbers-and-logical-operators/"&gt;binary&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Read more:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://docs.python.org/3.8/library/stdtypes.html#bytes"&gt;bytes in Python docs&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.python.org/3.8/library/string.html"&gt;String in Python docs&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>python</category>
    </item>
    <item>
      <title>string isupper() and islower() methods with examples</title>
      <dc:creator>natamacm</dc:creator>
      <pubDate>Tue, 09 Jun 2020 13:14:56 +0000</pubDate>
      <link>https://forem.com/natamacm/string-isupper-and-islower-methods-with-examples-hom</link>
      <guid>https://forem.com/natamacm/string-isupper-and-islower-methods-with-examples-hom</guid>
      <description>&lt;p&gt;&lt;a href="https://python.org" rel="noopener noreferrer"&gt;Python&lt;/a&gt; string isupper() and islower() methods with Examples.&lt;/p&gt;

&lt;p&gt;Python isupper() and islower() are in-built methods in Python, that are used to check if a &lt;a href="https://pythonbasics.org/strings/" rel="noopener noreferrer"&gt;string&lt;/a&gt; is in uppercase or lowercase.  Internally it uses an &lt;a href="https://python-commandments.org/python-if-else-elif-statement/" rel="noopener noreferrer"&gt;if statement&lt;/a&gt; that checks the characters.&lt;/p&gt;

&lt;h2&gt;
  
  
  String isupper() method
&lt;/h2&gt;

&lt;p&gt;isupper() returns "true" if all characters of the string are uppercase characters.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Syntax:&lt;/strong&gt;    &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; String.isupper()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Parameter:&lt;/strong&gt; &lt;br&gt;
None&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Return type:&lt;/strong&gt;  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;true&lt;/strong&gt; - if all characters of the string are uppercase characters.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;false&lt;/strong&gt;  - if any of the characters is not in uppercase character.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This works both in the Python &lt;a href="https://bsdnerds.org/learn-python/" rel="noopener noreferrer"&gt;shell&lt;/a&gt; and from a &lt;a href="https://pythonprogramminglanguage.com/how-to-run/" rel="noopener noreferrer"&gt;script&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Python Example:&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
The example below shows how to use the isupper() method. The method is applied to the string directly.&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%2Fthumbs.gfycat.com%2FExaltedFemaleAnemone-max-1mb.gif" 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%2Fthumbs.gfycat.com%2FExaltedFemaleAnemone-max-1mb.gif" alt="string"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So the methods isupper() and islower() both work with &lt;a href="https://pythonspot.com/python-strings/" rel="noopener noreferrer"&gt;strings&lt;/a&gt;.&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="c1"&gt;# s1 with all uppercase characters
&lt;/span&gt;&lt;span class="n"&gt;s1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;DEVTO&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;isupper&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;

&lt;span class="c1"&gt;# s2 with uppercase character, DOT, SPACE 
&lt;/span&gt;&lt;span class="n"&gt;s2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;DEV.TO&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;isupper&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;

&lt;span class="c1"&gt;# s3 with uppercase and lowercase characters
&lt;/span&gt;&lt;span class="n"&gt;s3&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;DEV.to&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s3&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;isupper&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;

&lt;span class="c1"&gt;# s4 with all lowercase characters
&lt;/span&gt;&lt;span class="n"&gt;s4&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;dev.to&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s4&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;isupper&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The program above outputs this:    &lt;/p&gt;

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

&lt;/div&gt;
&lt;h2&gt;
  
  
  2) String islower() method
&lt;/h2&gt;

&lt;p&gt;The method islower() returns "true" if all characters of the string are lowercase characters.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Syntax:&lt;/strong&gt;    &lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; String.islower()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Parameter:&lt;/strong&gt; &lt;br&gt;
None&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Return type:&lt;/strong&gt;  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;true&lt;/strong&gt; - if all characters of the string are lowercase characters.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;false&lt;/strong&gt; - if any of the characters is not in lowercase character.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Python Example:&lt;/strong&gt;&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="c1"&gt;# s1 with all uppercase characters
&lt;/span&gt;&lt;span class="n"&gt;s1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;DEVTO&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;islower&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;

&lt;span class="c1"&gt;# s2 with uppercase character, DOT, SPACE 
&lt;/span&gt;&lt;span class="n"&gt;s2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;DEV.TO&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;islower&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;

&lt;span class="c1"&gt;# s3 with uppercase and lowercase characters
&lt;/span&gt;&lt;span class="n"&gt;s3&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;DEV.to&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s3&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;islower&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;

&lt;span class="c1"&gt;# s4 with all lowercase characters
&lt;/span&gt;&lt;span class="n"&gt;s4&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;dev.to&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s4&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;islower&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The program above outputs this:    &lt;/p&gt;

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

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Read more:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://gumroad.com/l/dcsp" rel="noopener noreferrer"&gt;Python Crash Course for Beginners&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.python.org/3/library/string.html" rel="noopener noreferrer"&gt;Python doc on strings&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>python</category>
    </item>
    <item>
      <title>How to get the directory of the currently running file?</title>
      <dc:creator>natamacm</dc:creator>
      <pubDate>Fri, 22 May 2020 12:57:14 +0000</pubDate>
      <link>https://forem.com/natamacm/how-to-get-the-directory-of-the-currently-running-file-47mg</link>
      <guid>https://forem.com/natamacm/how-to-get-the-directory-of-the-currently-running-file-47mg</guid>
      <description>&lt;p&gt;The &lt;a href="https://golang.org/"&gt;Golang&lt;/a&gt; programming language makes it easy to build simple, reliable, and efficient software.  &lt;/p&gt;

&lt;p&gt;You can get the current directory of the program you are running (&lt;a href="https://golangr.com/hello-world/"&gt;run golang&lt;/a&gt;). &lt;/p&gt;

&lt;p&gt;So how to find out where the executable is?&lt;/p&gt;

&lt;p&gt;As usual in programming languages, there are several ways to do this.&lt;br&gt;
It's not Go specific, as you can have the same problem when programming C or C++. &lt;/p&gt;

&lt;p&gt;To get the directory of the executable you can use "path/filepath.Dir".&lt;/p&gt;

&lt;p&gt;For Go 1.8 and above you can use os.Executable for getting executable path&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;package&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;                                                                                                                               

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;                                                                                                                                   
    &lt;span class="s"&gt;"fmt"&lt;/span&gt;                                                                                                                                  
    &lt;span class="s"&gt;"os"&lt;/span&gt;                                                                                                                                   
    &lt;span class="s"&gt;"path/filepath"&lt;/span&gt;                                                                                                                        
&lt;span class="p"&gt;)&lt;/span&gt;                                                                                                                                          

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;                                                                                                                              
    &lt;span class="n"&gt;ex&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Executable&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;err&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="no"&gt;nil&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;                                                                                                                        
        &lt;span class="nb"&gt;panic&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;err&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;                                                                                                                         
    &lt;span class="p"&gt;}&lt;/span&gt;                                                                                                                                      
    &lt;span class="n"&gt;exePath&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;filepath&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Dir&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ex&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;                                                                                                            
    &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;exePath&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;                                                                                                                   
&lt;span class="p"&gt;}&lt;/span&gt;    
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;An alternative way to do this is with this code, it returns the current working directory:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;package&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="s"&gt;"fmt"&lt;/span&gt;
    &lt;span class="s"&gt;"os"&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;pwd&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Getwd&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;err&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="no"&gt;nil&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;err&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Exit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;pwd&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;You can also do it this way:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="s"&gt;"fmt"&lt;/span&gt;
    &lt;span class="s"&gt;"log"&lt;/span&gt;
    &lt;span class="s"&gt;"os"&lt;/span&gt;
    &lt;span class="s"&gt;"path/filepath"&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;func&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nb"&gt;dir&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;filepath&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Abs&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;filepath&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Dir&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Args&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&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;err&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="n"&gt;nil&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="n"&gt;log&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Fatal&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;err&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;dir&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



</description>
      <category>go</category>
    </item>
    <item>
      <title>Should I use Kivy or PyQT for GUI?</title>
      <dc:creator>natamacm</dc:creator>
      <pubDate>Thu, 21 May 2020 14:46:07 +0000</pubDate>
      <link>https://forem.com/natamacm/should-i-use-kivy-or-pyqt-for-gui-h6</link>
      <guid>https://forem.com/natamacm/should-i-use-kivy-or-pyqt-for-gui-h6</guid>
      <description>&lt;p&gt;&lt;a href="https://qt.io" rel="noopener noreferrer"&gt;Qt&lt;/a&gt; is a world-class, powerhouse GUI toolkit. Kivy is the new kid on the block. &lt;a href="https://kivy.org" rel="noopener noreferrer"&gt;Kivy&lt;/a&gt; is beginner friendly and cross-platform, but so is PyQt. So what to choose?&lt;/p&gt;

&lt;p&gt;On the desktop, PyQt is better because you can get a near-native look and feel easy and you have a simple &lt;a href="https://pythonbasics.org/qt-designer-python/" rel="noopener noreferrer"&gt;gui designer&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;But on mobile, it makes more sense to go with Kivy. Kivy is more oriented towards mobile interfaces.&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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F1pcq6yse3oc5kgqczb20.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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F1pcq6yse3oc5kgqczb20.png" alt="python kivy"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;PyQt is more oriented towards desktop software.&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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fu3nz31ompmgh47oj6nr9.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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fu3nz31ompmgh47oj6nr9.png" alt="pyqt"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When it comes to licensing, PyQt requires payment for commercial applications. Kivy on the other hand is free for all types of applications.&lt;/p&gt;

&lt;p&gt;Kivy is a python UI framework not a wrappper around an UI library. Pyqt on the other hand is a wrapper around the QT UI library. But PyQt is not only a UI library, it can also do networking, databases and other things.&lt;/p&gt;

&lt;p&gt;PyQt is a mature module for building GUIs and other things, it is continuously developed and has been around for a long time. That means it's easy to find developers that have experience with PyQt/Qt.&lt;/p&gt;

&lt;h2&gt;
  
  
  Learning resources
&lt;/h2&gt;

&lt;p&gt;So how do you get started with building GUI applications with Python?&lt;br&gt;
First you should know Python programming itself. Then you can learn either GUI framework.&lt;/p&gt;

&lt;p&gt;Here are some useful links for PyQt&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://gum.co/pysqtsamples" rel="noopener noreferrer"&gt;PyQt course and book&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://pythonbasics.org/#PyQt" rel="noopener noreferrer"&gt;PyQt articles&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://pythonpyqt.com/" rel="noopener noreferrer"&gt;Python PyQt examples&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://pythonprogramminglanguage.com/pyqt/" rel="noopener noreferrer"&gt;PyQt tutorials&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://pythonspot.com/gui/" rel="noopener noreferrer"&gt;PyQt and other GUI tutorials&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For Kivy, these learning resources are available:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://kivy.org/doc/stable/tutorials-index.html" rel="noopener noreferrer"&gt;Kivy tutorial&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/watch?v=bMHK6NDVlCM" rel="noopener noreferrer"&gt;Kivy lesson&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>python</category>
    </item>
    <item>
      <title>Which one should I use for GUI wxpython or pyqt? </title>
      <dc:creator>natamacm</dc:creator>
      <pubDate>Thu, 21 May 2020 14:18:01 +0000</pubDate>
      <link>https://forem.com/natamacm/which-one-should-i-use-for-gui-wxpython-or-pyqt-238k</link>
      <guid>https://forem.com/natamacm/which-one-should-i-use-for-gui-wxpython-or-pyqt-238k</guid>
      <description>&lt;p&gt;First let's compare the two so that you can make an informed decision. Both can be used to create GUI applications with Python.&lt;/p&gt;

&lt;p&gt;That being said, PyQt has a lot of software available and a lot of learning resources. wxPython on the other hand seems more hobbyist, the amount of learning material is simply no match.&lt;/p&gt;

&lt;h2&gt;
  
  
  Programming methodology
&lt;/h2&gt;

&lt;p&gt;PyQt and WxWidgets are both object oriented. That means you have to know about &lt;a href="https://pythonprogramminglanguage.com/class/"&gt;classes and objects&lt;/a&gt; when programming either one of them. &lt;/p&gt;

&lt;p&gt;Because everything in Python is an object it makes sense to know object orientated programming.&lt;/p&gt;

&lt;h2&gt;
  
  
  Look and feel
&lt;/h2&gt;

&lt;p&gt;wxPython uses the native toolkit on each operating system. This may cause some widgets to be available on one platform but not on the other. &lt;/p&gt;

&lt;p&gt;PyQt uses the "Qt" style and you can &lt;a href="https://pythonbasics.org/pyqt-style/"&gt;change the style&lt;/a&gt; you use for your Qt applications. &lt;/p&gt;

&lt;p&gt;Some of the available styles are (depending on your operating system):&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;'Breeze'&lt;/li&gt;
&lt;li&gt;'Oxygen'&lt;/li&gt;
&lt;li&gt;'QtCurve'&lt;/li&gt;
&lt;li&gt;'Windows'&lt;/li&gt;
&lt;li&gt;'Fusion'&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--9UE1IBTB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/hnyzbqf90a0y2c2nv57t.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--9UE1IBTB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/hnyzbqf90a0y2c2nv57t.png" alt="pyqt style"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  GUI module
&lt;/h2&gt;

&lt;p&gt;PyQt provides you with the concept of signals/slots that let you build your project as a set of components. WxPython on the other hand uses &lt;a href="https://pythonspot.com/wxpython-buttons/"&gt;callbacks&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;PyQt comes with a &lt;a href="https://pythonbasics.org/qt-designer-python/"&gt;designer program&lt;/a&gt; that lets you build any desktop software. WxWidgets or wxPython on the other hand, has some third party designers but they don't match the amount of features PyQt has.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--236ppyOr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/oscednya63igu91t9xdr.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--236ppyOr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/oscednya63igu91t9xdr.jpg" alt="pyqt designer"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Why PyQt?
&lt;/h2&gt;

&lt;p&gt;PyQt is not only a GUI library, it can do databases, networking and a lot more. At the same time, wxPython is only for GUI programming.&lt;/p&gt;

&lt;p&gt;PyQt has a lot of example &lt;a href="https://pythonpyqt.com/"&gt;howtos&lt;/a&gt; and books, the amount of learning material is a lot larger for PyQt than wxPython.&lt;/p&gt;

&lt;p&gt;If you are new to PyQt, I recommend this &lt;a href="https://gumroad.com/l/pysqtsamples"&gt;PyQt book&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>python</category>
    </item>
    <item>
      <title>Should I learn golang?</title>
      <dc:creator>natamacm</dc:creator>
      <pubDate>Wed, 20 May 2020 18:24:06 +0000</pubDate>
      <link>https://forem.com/natamacm/should-i-learn-golang-co6</link>
      <guid>https://forem.com/natamacm/should-i-learn-golang-co6</guid>
      <description>&lt;p&gt;Yes, it never hurts to learn a new language and Go is great at concurrency. Go (Golang) is an open-source programming language. It creates binaries from code and is not interpreted.&lt;/p&gt;

&lt;p&gt;Go language is developed at Google and in syntax it's similar to C. But unlike C, it does memory management for you. It's great for building a back-end and is easy to deploy in the cloud.&lt;/p&gt;

&lt;p&gt;The Go programming language has tools that let developers use memory in a secure way, collect garbage, manage objects, and allows them to type statically with concurrency.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;So how to get started with Go?&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;For beginners, try the tutorial at &lt;a href="https://golangr.com/"&gt;golangr.com&lt;/a&gt;. It's a brief tutorial that goes over the basics.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Do the &lt;a href="https://tour.golang.org/"&gt;Go tour&lt;/a&gt;, which is like an interactive slide show. It also goes over the basics&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Go through &lt;a href="http://www.golangbootcamp.com/book/"&gt;this book&lt;/a&gt; to learn more about Go&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Go through some books like&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;Go in Action by William Kennedy, Brian Ketelsen, Erik St. Martin&lt;/li&gt;
&lt;li&gt;Learning Functional Programming in Go by Lex Sheehan&lt;/li&gt;
&lt;li&gt;The Go Programming Language by Alan A. A. Donovan and Brian W. Kernighan&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;There is no official Golang examination, but there are some companies offering training. These companies are not affiliated with Google.&lt;/p&gt;

</description>
      <category>go</category>
    </item>
    <item>
      <title>File checksum</title>
      <dc:creator>natamacm</dc:creator>
      <pubDate>Sat, 16 May 2020 18:45:05 +0000</pubDate>
      <link>https://forem.com/natamacm/file-checksum-39o5</link>
      <guid>https://forem.com/natamacm/file-checksum-39o5</guid>
      <description>&lt;p&gt;A checksum is a sequence of numbers and letters used to check data for errors. You can generate a checksum for any file. &lt;/p&gt;

&lt;p&gt;The generation of a checksum is called hashing and is done by a &lt;a href="https://en.wikipedia.org/wiki/Hash_function"&gt;hashing algorithm&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--95Thh_BJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/kbhv4s96zf15ft1dm6q2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--95Thh_BJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/kbhv4s96zf15ft1dm6q2.png" alt="hashing"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You should know that hashing is not encryption. It just creates a hash, but it's impossible to reverse the process, unlike with encryption that requires a key to recreate the plain text.&lt;/p&gt;

&lt;p&gt;You can get the checksum of any file in &lt;a href="https://python.org"&gt;Python&lt;/a&gt;. There are several algorithms you can use. One of the older ones is &lt;a href="https://gitpress.io/u/1246/python-script-get_file_checksum"&gt;md5&lt;/a&gt;. It's an older algorithm and I recommend newer ones. In fact md5 is from 1992 and it's better avoided.&lt;/p&gt;

&lt;p&gt;To see a comparison of algorithms and attacks, check &lt;a href="https://en.wikipedia.org/wiki/Template:Comparison_of_SHA_functions"&gt;this page&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You could use the sha256 algorithm to find a file checksum:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# Python program to find SHA256 hash string of a file
&lt;/span&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;hashlib&lt;/span&gt;

&lt;span class="n"&gt;filename&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;input&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Enter the input file name: "&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;sha256_hash&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;hashlib&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sha256&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="k"&gt;with&lt;/span&gt; &lt;span class="nb"&gt;open&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;filename&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="s"&gt;"rb"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="c1"&gt;# Read and update hash string value in blocks of 4K
&lt;/span&gt;    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;byte_block&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="nb"&gt;iter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;lambda&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;read&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;4096&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;&lt;span class="s"&gt;b""&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="n"&gt;sha256_hash&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;update&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;byte_block&lt;/span&gt;&lt;span class="p"&gt;)&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;sha256_hash&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;hexdigest&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;a href="https://docs.python.org/2/library/hashlib.html#module-hashlib"&gt;Hashlib&lt;/a&gt; has many implementations of hashing algorithms, you can see that in the Python shell:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; import hashlib
&amp;gt;&amp;gt;&amp;gt; hashlib.algorithms_available
{'sha256', 'blake2s', 'blake2b', 'sha384', 'md5', 'sha3_256', 'sha3_224', 'sha1', 'shake_256', 'sha3_512', 'shake_128', 'sha3_384', 'sha224', 'sha512'}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



</description>
      <category>python</category>
    </item>
    <item>
      <title>Detect any color with Python</title>
      <dc:creator>natamacm</dc:creator>
      <pubDate>Wed, 13 May 2020 15:30:40 +0000</pubDate>
      <link>https://forem.com/natamacm/detect-any-color-with-python-2j23</link>
      <guid>https://forem.com/natamacm/detect-any-color-with-python-2j23</guid>
      <description>&lt;p&gt;You can detect any color with &lt;a href="https://python.org"&gt;Python&lt;/a&gt;. That can be a color of any object defined as string, like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;fish&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;WhatColorIsX&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;new&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'fish'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;What it's doing behind the scenes is use Google Image API.&lt;/p&gt;

&lt;h3&gt;
  
  
  Installation
&lt;/h3&gt;

&lt;p&gt;You can install the module &lt;code&gt;WhatColorIsX&lt;/code&gt; with &lt;a href="https://pythonbasics.org/how-to-use-pip-and-pypi/"&gt;pip&lt;/a&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ pip install WhatColorIsX
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;You may find you need to pip install Pillow as a dependency first, although it will be attempted automatically.&lt;/p&gt;

&lt;h2&gt;
  
  
  Import to your project
&lt;/h2&gt;

&lt;p&gt;For almost all cases, call the new() factory function, then get the colour value from the color() method:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;WhatColorIsX&lt;/span&gt;

&lt;span class="n"&gt;brick&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;WhatColorIsX&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;new&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'brick'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;brick_color&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;brick&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;color&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="n"&gt;fish&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;WhatColorIsX&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;new&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'fish'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;fish_color_bright&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;fish&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;color&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;bright_hue&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;If you already have PIL images that you want to process, you can use the same syntax:&lt;br&gt;
&lt;/p&gt;

&lt;div class="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;WhatColorIsX&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;whatcoloris_image&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="nn"&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="n"&gt;img&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="nb"&gt;open&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'images/cat.jpg'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;cat&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;WhatColorIsX&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;new&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;img&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;cat_color&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;cat&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;color&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



</description>
      <category>python</category>
    </item>
    <item>
      <title>Terminal image with Python</title>
      <dc:creator>natamacm</dc:creator>
      <pubDate>Wed, 13 May 2020 15:26:35 +0000</pubDate>
      <link>https://forem.com/natamacm/terminal-image-with-python-44mh</link>
      <guid>https://forem.com/natamacm/terminal-image-with-python-44mh</guid>
      <description>&lt;p&gt;You can display an image in terminal. Using &lt;a href="https://python.org"&gt;Python&lt;/a&gt; you can use the module &lt;code&gt;timg&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Setup
&lt;/h2&gt;

&lt;p&gt;timg is available as a package on PyPI. You can install it with &lt;a href="https://pythonbasics.org/how-to-use-pip-and-pypi/"&gt;pip&lt;/a&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ pip install timg
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Now you can use the timg command in your terminal.&lt;/p&gt;

&lt;h2&gt;
  
  
  usage
&lt;/h2&gt;

&lt;p&gt;To display an image from code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;timg&lt;/span&gt;

&lt;span class="n"&gt;obj&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;timg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Renderer&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;                                                                                               
&lt;span class="n"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;load_image_from_file&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"test.png"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;                                                                                
&lt;span class="n"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;resize&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;40&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;render&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;timg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ASCIIMethod&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;That turns the image into ascii art.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--pnQc0dBo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/3hd9joel1q6ljza7nfqn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--pnQc0dBo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/3hd9joel1q6ljza7nfqn.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To run it as command line program:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    usage: timg [-h] [-V] [-i] [-m METHOD] [-r N] [-s W] [filename]

    print an image in terminal


    positional arguments:
      filename              filename of an image

    optional arguments:
      -h, --help            show this help message and exit
      -V, --version         print version and exit
      -i, --invert-background
                            invert grayscale in ASCII mode
      -m METHOD, --method METHOD
                            name of a rendering method (use `-m list` to list
                            available methods, the default is a24h)
      -r N, --reduce-colors N

                            reduce color palette of an input image (1-256)
      -s W, --size W        width of an image
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



</description>
      <category>python</category>
    </item>
  </channel>
</rss>
