<?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>DEV Community: petercour</title>
    <description>The latest articles on DEV Community by petercour (@petercour).</description>
    <link>https://dev.to/petercour</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%2F145184%2Faab742e4-5afa-487b-b0a1-9f74ddec3d6c.png</url>
      <title>DEV Community: petercour</title>
      <link>https://dev.to/petercour</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/petercour"/>
    <language>en</language>
    <item>
      <title>Python as terminal commands</title>
      <dc:creator>petercour</dc:creator>
      <pubDate>Thu, 25 Jul 2019 20:30:04 +0000</pubDate>
      <link>https://dev.to/petercour/python-as-terminal-commands-26ii</link>
      <guid>https://dev.to/petercour/python-as-terminal-commands-26ii</guid>
      <description>&lt;p&gt;Python is often used when creating scripts. But did you know you can run it straight from the command line?&lt;/p&gt;

&lt;p&gt;No, I don't mean running a .py file from the command, but running a program input.&lt;/p&gt;

&lt;h3&gt;
  
  
  Whats Python?
&lt;/h3&gt;

&lt;p&gt;Python is a programming language. &lt;/p&gt;

&lt;p&gt;The code below won't make sense if you don't know the &lt;a href="https://pythonprogramminglanguage.com/" rel="noopener noreferrer"&gt;Python&lt;/a&gt; programming language. You should be familiar with the idea of for loops.&lt;/p&gt;

&lt;h3&gt;
  
  
  Python code as command
&lt;/h3&gt;

&lt;p&gt;You can run Python on a single line with command line as input, like this:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;python -c "for i in range(1,10): print(i)"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;This then outputs the numbers.&lt;br&gt;
Now you can use the alias command to create custom commands that run this python command&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;alias forloop='python -c "for i in range(1,10): print(i)"'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Then in your terminal&lt;/p&gt;

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

&lt;/div&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%2Fproxy.duckduckgo.com%2Fiu%2F%3Fu%3Dhttps%253A%252F%252Fmedia.giphy.com%252Fmedia%252F3oKIPnAiaMCws8nOsE%252Fgiphy.gif%26f%3D1" 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%2Fproxy.duckduckgo.com%2Fiu%2F%3Fu%3Dhttps%253A%252F%252Fmedia.giphy.com%252Fmedia%252F3oKIPnAiaMCws8nOsE%252Fgiphy.gif%26f%3D1"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can store these commands in your .bashrc file.&lt;/p&gt;

&lt;p&gt;Is this a good idea? from a security point of view probably not. &lt;br&gt;
See &lt;a href="https://dev.to/petercour/inject-code-in-python-process-3cfh"&gt;Inject code in Python process&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>python</category>
    </item>
    <item>
      <title>Deep Learning, Object detection with Python</title>
      <dc:creator>petercour</dc:creator>
      <pubDate>Thu, 25 Jul 2019 18:01:56 +0000</pubDate>
      <link>https://dev.to/petercour/deep-learning-object-detection-with-python-20mh</link>
      <guid>https://dev.to/petercour/deep-learning-object-detection-with-python-20mh</guid>
      <description>&lt;p&gt;Luminoth is a Deep Learning toolkit for Computer Vision. It uses tensorflow underneath, so install tensorflow or tensorflow-gpu (if you have a gpu).&lt;/p&gt;

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

&lt;/div&gt;

&lt;p&gt;One of these then&lt;/p&gt;

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

&lt;/div&gt;

&lt;p&gt;One of the things you'll need is a faster computer (and probably a GPU). In my case, running scripts like this sometimes freezes my computer.&lt;/p&gt;

&lt;p&gt;Download an image, like this one&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.pixabay.com%2Fphoto%2F2016%2F01%2F25%2F15%2F33%2Fbicycling-1160860_960_720.jpg" 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.pixabay.com%2Fphoto%2F2016%2F01%2F25%2F15%2F33%2Fbicycling-1160860_960_720.jpg"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then run the command&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;lumi predict bicycling-1160860_960_720.jpg
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Then confirm you want to download&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Checkpoint not found. Check remote repository? [y/N]: y
Retrieving remote index... done.
2 new remote checkpoints added.
Checkpoint not present locally. Want to download it? [y/N]: y
Downloading checkpoint...  [####################################]  100%
Importing checkpoint... done.
Checkpoint imported successfully.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Results in this json output:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{"objects": [{"prob": 0.9997, "bbox": [294.0, 231.0, 468.0, 536.0], "label": "person"}, {"prob": 0.9971, "bbox": [494.0, 289.0, 578.0, 439.0], "label": "person"}, {"prob": 0.997, "bbox": [727.0, 303.0, 800.0, 465.0], "label": "person"}, {"prob": 0.9965, "bbox": [555.0, 315.0, 652.0, 560.0], "label": "person"}, {"prob": 0.9934, "bbox": [569.0, 425.0, 636.0, 600.0], "label": "bicycle"}, {"prob": 0.9932, "bbox": [326.0, 410.0, 426.0, 582.0], "label": "bicycle"}, {"prob": 0.9334, "bbox": [744.0, 380.0, 784.0, 482.0], "label": "bicycle"}, {"prob": 0.8723, "bbox": [506.0, 360.0, 565.0, 480.0], "label": "bicycle"}, {"prob": 0.8142, "bbox": [848.0, 319.0, 858.0, 342.0], "label": "person"}], "file": "bicycling-1160860_960_720.jpg"}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;You can get the list of checkpoints&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;lumi checkpoint list
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;you can run the progrma&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#!/usr/bin/python
from luminoth import Detector, read_image, vis_objects

image = read_image('traffic-image.png')
detector = Detector(checkpoint='traffic')
objects = detector.predict(image)

print(objects)

vis_objects(image, objects).save('traffic-out.png')
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;then outputs the objects like above.&lt;/p&gt;

&lt;p&gt;Related links:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://tryolabs.com/blog/2018/04/17/announcing-luminoth-0-1/" rel="noopener noreferrer"&gt;Luminoth module&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://pythonprogramminglanguage.com/" rel="noopener noreferrer"&gt;Python tutorial&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>python</category>
      <category>machinelearning</category>
      <category>deeplearning</category>
    </item>
    <item>
      <title>Listing files, dirs and subdirs with Python</title>
      <dc:creator>petercour</dc:creator>
      <pubDate>Thu, 25 Jul 2019 15:29:54 +0000</pubDate>
      <link>https://dev.to/petercour/listing-files-dirs-and-subdirs-with-python-3gni</link>
      <guid>https://dev.to/petercour/listing-files-dirs-and-subdirs-with-python-3gni</guid>
      <description>&lt;p&gt;If you know Python programming, there's a lot of things you can do. You can use the os module to list all files in the directory (including subdirectories).&lt;/p&gt;

&lt;p&gt;If you use Linux or Mac, you can even list every file on your computer (search from /). Or you could browse from your home directory.&lt;/p&gt;

&lt;p&gt;If you want all files from the current directory and subdirs, use '.'.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#!/usr/bin/python3
import os
path = '.'
for dirpath, dirname, filenames in os.walk(path):
    for filename in filenames:
        print(os.path.join(dirpath,filename))
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;This lists all files in the directory, including all hidden files.&lt;br&gt;
For readability you can change it to:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#!/usr/bin/python3
...
    file_and_path = os.path.join(dirpath,filename)
    print(file_and_path)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h3&gt;
  
  
  File interaction
&lt;/h3&gt;

&lt;p&gt;You can show only specific files and interact with them. For instance, you can show every image on your computer&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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Ffk2f1icapuc3hp32nov2.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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Ffk2f1icapuc3hp32nov2.png"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#!/usr/bin/python3
import os
import cv2
import time

path = '/home/linux/Desktop'
for dirpath, dirname, filenames in os.walk(path):
    for filename in filenames:
        file_and_path = os.path.join(dirpath,filename)
        if ".jpg" in file_and_path or ".jpeg" in file_and_path:
            print(file_and_path)

            try:
                # show image
                image = cv2.imread(file_and_path)
                cv2.imshow(file_and_path, image)
                cv2.waitKey(2000)
                cv2.destroyAllWindows()
                #time.sleep(1)
            except:
                print('Error loading image ' + file_and_path)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Related links:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://pythonbasics.org/" rel="noopener noreferrer"&gt;Learn Python&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://pythonbasics.org/exercises/" rel="noopener noreferrer"&gt;Python exercises&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>python</category>
      <category>files</category>
    </item>
    <item>
      <title>Inject code in Python process</title>
      <dc:creator>petercour</dc:creator>
      <pubDate>Thu, 25 Jul 2019 14:46:06 +0000</pubDate>
      <link>https://dev.to/petercour/inject-code-in-python-process-3cfh</link>
      <guid>https://dev.to/petercour/inject-code-in-python-process-3cfh</guid>
      <description>&lt;p&gt;Python is widely used for software development. By universities, companies and many more. So is Python an utopia that will solve all computer problems?&lt;/p&gt;

&lt;p&gt;Did you know you can inject code into a running Python process?  You can use &lt;a href="http://pyrasite.com" rel="noopener noreferrer"&gt;Pyrasite&lt;/a&gt; for that. This needs Python 2.4 or higher.&lt;/p&gt;

&lt;p&gt;You can watch a demo here: &lt;a href="https://asciinema.org/a/1148/embed?" rel="noopener noreferrer"&gt;demo&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://asciinema.org/a/1148/embed?" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fk47q7rdahui7wvkyjiw7.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It comes with several programs, including a shell&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ pyrasite-shell
Usage: pyrasite-shell &amp;lt;PID&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;So you can inject a payload&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ pyrasite &amp;lt;PID&amp;gt; payload.py
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;You can find some &lt;a href="https://pyrasite.readthedocs.io/en/latest/Payloads.html" rel="noopener noreferrer"&gt;example payloads here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;So if you have the process id , you can inject anything into the running program.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://camo.githubusercontent.com/c83384d57d36599ec73d501067b08e3c883b9252/687474703a2f2f6c65776b2e6f72672f696d672f70797261736974652f70797261736974652d696e666f2e706e67" class="article-body-image-wrapper"&gt;&lt;img src="https://camo.githubusercontent.com/c83384d57d36599ec73d501067b08e3c883b9252/687474703a2f2f6c65776b2e6f72672f696d672f70797261736974652f70797261736974652d696e666f2e706e67"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There's also a &lt;a href="https://github.com/lmacken/pyrasite-gui" rel="noopener noreferrer"&gt;GUI&lt;/a&gt;. It lets you easily monitor, analyze, introspect, and alter running Python programs.&lt;/p&gt;

&lt;p&gt;Related links:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://github.com/lmacken/pyrasite" rel="noopener noreferrer"&gt;Pyrasite project&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://pythonbasics.org/" rel="noopener noreferrer"&gt;Learn Python&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://pythonbasics.org/exercises/" rel="noopener noreferrer"&gt;Python exercises&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>python</category>
      <category>programming</category>
    </item>
    <item>
      <title>What is kmeans?</title>
      <dc:creator>petercour</dc:creator>
      <pubDate>Wed, 24 Jul 2019 16:13:39 +0000</pubDate>
      <link>https://dev.to/petercour/what-is-kmeans-3e27</link>
      <guid>https://dev.to/petercour/what-is-kmeans-3e27</guid>
      <description>&lt;p&gt;kmeans is a clustering algorithm for &lt;a href="https://pythonprogramminglanguage.com/python-machine-learning/" rel="noopener noreferrer"&gt;Machine Learning&lt;/a&gt; purposes. A cluster is another word for group.&lt;/p&gt;

&lt;p&gt;So what do I mean with kmeans?&lt;/p&gt;

&lt;h3&gt;
  
  
  Starting situation
&lt;/h3&gt;

&lt;p&gt;The goal of the algorithm is to find groups in datapoints.  In the context of machine learning, you measure data.&lt;/p&gt;

&lt;p&gt;For instance, you could measure height and salary. Then you would have 2d vectors (height,salary) that you could plot on a 2d plot.&lt;/p&gt;

&lt;p&gt;There are K groups, or formally, K clusters. There must be at least 2 groups, because 1 group doesn't need the algorithm to run.&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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fkfuoau5ga91ehrpx681x.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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fkfuoau5ga91ehrpx681x.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  End goal
&lt;/h3&gt;

&lt;p&gt;Based on the previous input (the data points). Then the algorithm will find K groups, in this case K=3.&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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F3uklv1e2xs8xcez5tkba.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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F3uklv1e2xs8xcez5tkba.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So now if you have a new data point, the group that's closest is the type. Which K is best? that's a bit of a searching quest.&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%2Fproxy.duckduckgo.com%2Fiu%2F%3Fu%3Dhttps%253A%252F%252Fmedia.giphy.com%252Fmedia%252FpnzUNWmqaPE4w%252Fgiphy.gif%26f%3D1" 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%2Fproxy.duckduckgo.com%2Fiu%2F%3Fu%3Dhttps%253A%252F%252Fmedia.giphy.com%252Fmedia%252FpnzUNWmqaPE4w%252Fgiphy.gif%26f%3D1"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  The code
&lt;/h3&gt;

&lt;p&gt;The program below uses Machine Learning and the modules sklearn, matplotlib to create the plots and run the kmeans algorithm. It creates the images shown in this article.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#!/usr/bin/python3
from sklearn.datasets import make_blobs
from matplotlib import pyplot as plt
from sklearn.cluster import KMeans

X, y = make_blobs(n_samples=200,
                  n_features=2,
                  centers=4,
                  cluster_std=1,
                  center_box=(-10.0, 10.0),
                  shuffle=True,
                  random_state=1)

plt.figure(figsize=(6, 4), dpi=144)
plt.xticks(())
plt.yticks(())
plt.scatter(X[:, 0],X[:, 1], s=20, marker='o')
plt.show()

n_cluster = 3
k_means = KMeans(n_clusters=n_cluster)
k_means.fit(X)
print("kmean: k={}, cost={}".format(n_cluster, int(k_means.score(X))))

labels = k_means.labels_
centers = k_means.cluster_centers_

markers = ['o', '^', '*']
colors = ['r', 'b', 'y']

plt.figure(figsize=(6, 4), dpi=144)
plt.xticks(())
plt.yticks(())

for c in range(n_cluster):
    cluster = X[labels == c]
    plt.scatter(cluster[:, 0], cluster[:, 1], marker=markers[c], s=20, c=colors[c])

plt.scatter(centers[:, 0], centers[:, 1], marker='o', c='white', alpha=0.9, s=300)
for i, c in enumerate(centers):
    plt.scatter(c[0], c[1], marker='$%d$' % i, s=50, c=colors[i])

plt.show()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Related links:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://scikit-learn.org/stable/index.html" rel="noopener noreferrer"&gt;Sklearn machine learning module&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://pythonprogramminglanguage.com/python-machine-learning/" rel="noopener noreferrer"&gt;Machine Learning articles&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://pythonprogramminglanguage.com/python-machine-learning/" rel="noopener noreferrer"&gt;Text clustering with kmeans&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://gumroad.com/l/MnRYU" rel="noopener noreferrer"&gt;Machine Learning course and examples&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>python</category>
      <category>ai</category>
      <category>machinelearning</category>
    </item>
    <item>
      <title>Translate with the snake (Python)</title>
      <dc:creator>petercour</dc:creator>
      <pubDate>Wed, 24 Jul 2019 15:20:16 +0000</pubDate>
      <link>https://dev.to/petercour/translate-with-the-snake-4i04</link>
      <guid>https://dev.to/petercour/translate-with-the-snake-4i04</guid>
      <description>&lt;p&gt;There are some sites that offer language translation. You may know Google translate which is one of them.&lt;/p&gt;

&lt;p&gt;Did you know you can use those sites from &lt;a href="https://pythonprogramminglanguage.com/" rel="noopener noreferrer"&gt;Python&lt;/a&gt; code? Welcome to the jungle!&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%2Fproxy.duckduckgo.com%2Fiu%2F%3Fu%3Dhttps%253A%252F%252Fmedia.giphy.com%252Fmedia%252FzC4YhpDY76OxW%252Fgiphy.gif%26f%3D1" 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%2Fproxy.duckduckgo.com%2Fiu%2F%3Fu%3Dhttps%253A%252F%252Fmedia.giphy.com%252Fmedia%252FzC4YhpDY76OxW%252Fgiphy.gif%26f%3D1"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To do so you need the modules requests and BeautifulSoup. These modules are used to make the web request and fetch data. The example code below translate a string from English to French.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#!/usr/bin/python3
import requests
from bs4 import BeautifulSoup

def getHTMLText(url):
    try:
        r = requests.get(url, timeout=30)
        r.raise_for_status()
        return r.text
    except:
        print("Get HTML Failed!")
        return 0

def google_translate(to_translate, from_language="en", to_language="fr"):
    base_url = "https://translate.google.com/m?hl={}&amp;amp;sl={}&amp;amp;ie=UTF-8&amp;amp;q={}"
    url = base_url.format(to_language, from_language, to_translate)

    html = getHTMLText(url)
    if html:
        soup = BeautifulSoup(html, "html.parser")

    try:
        result = soup.find_all("div", {"class":"t0"})[0].text
    except:
        print("Translation Failed!")
        result = ""

    return result

if __name__ == '__main__':
    print(google_translate("Hello World!"))
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The important part here is the last line, a function call to google_translate with the text to translate as parameter.&lt;/p&gt;

&lt;p&gt;If you run it:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;python3 example.py
Bonjour le monde!
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Related links:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://pypi.org/project/beautifulsoup4/" rel="noopener noreferrer"&gt;BeautifulSoup module, web scraping&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://pythonprogramminglanguage.com/" rel="noopener noreferrer"&gt;Learn Python programming&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://pythonprogramminglanguage.com/speech-recognition/" rel="noopener noreferrer"&gt;Speech recognition, text to speech&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>python</category>
    </item>
    <item>
      <title>Read data with pandas</title>
      <dc:creator>petercour</dc:creator>
      <pubDate>Wed, 24 Jul 2019 15:05:31 +0000</pubDate>
      <link>https://dev.to/petercour/read-data-with-pandas-48dn</link>
      <guid>https://dev.to/petercour/read-data-with-pandas-48dn</guid>
      <description>&lt;p&gt;In &lt;a href="https://pythonbasics.org" rel="noopener noreferrer"&gt;Python&lt;/a&gt; there's a module that helps you parse data. Data can be in many forms (files, tables, excel, sql, json). There exists so many data sources for historic reasons.&lt;/p&gt;

&lt;p&gt;That module to work with data is named the &lt;a href="https://pandas.pydata.org/" rel="noopener noreferrer"&gt;pandas module&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;You may know you can use the Pandas module for data analysis. But did you know there are many ways to read data?&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pd.read_csv(filename)
pd.read_table(filename)
pd.read_excel(filename)
pd.read_sql(query, connection_object)
pd.read_json(json_string)
pd.read_html(url)
pd.read_clipboard()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&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%2Fproxy.duckduckgo.com%2Fiu%2F%3Fu%3Dhttps%253A%252F%252Fmedia.giphy.com%252Fmedia%252Fl4FGvUYI0tETAQwGk%252Fgiphy.gif%26f%3D1" 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%2Fproxy.duckduckgo.com%2Fiu%2F%3Fu%3Dhttps%253A%252F%252Fmedia.giphy.com%252Fmedia%252Fl4FGvUYI0tETAQwGk%252Fgiphy.gif%26f%3D1"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Yes, you can read data from many sources. These methods allow you to quickly grab your data&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#!/usr/bin/python3 
import pandas as pd
data = pd.read_csv('yourfile.csv', header=None)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;If you are using MySQL as source&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#!/usr/bin/python3
db = MySQLDatabase(DATABASE_HOST, DATABASE_USER, DATABASE_PASSWORD, DATABASE_NAME)
db_work_view = db.get_work_view()
connection = db_work_view._db_connection
df_people = pd.read_sql('select * from people', connection)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Reading an excel file&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;df = pd.read_excel('File.xlsx', sheetname='Sheet1')
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Well you get the idea. Pandas allows you to quickly fetch data from different data sources. It includes most of the existing data sources.&lt;/p&gt;

&lt;p&gt;Related links:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://pandas.pydata.org/" rel="noopener noreferrer"&gt;Python Data Analysis Library&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://pythonbasics.org" rel="noopener noreferrer"&gt;Learn Python programming&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://pythonbasics.org/exercises/" rel="noopener noreferrer"&gt;Python exercises&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>python</category>
      <category>data</category>
    </item>
    <item>
      <title>Bulk converts files to QR codes</title>
      <dc:creator>petercour</dc:creator>
      <pubDate>Wed, 24 Jul 2019 14:46:37 +0000</pubDate>
      <link>https://dev.to/petercour/bulk-converts-files-to-qr-codes-15mm</link>
      <guid>https://dev.to/petercour/bulk-converts-files-to-qr-codes-15mm</guid>
      <description>&lt;p&gt;What's the craziest way to take backups? The cloud? floppy disks? QR codes?&lt;/p&gt;

&lt;p&gt;QR codes started with the Japanese automobile industry. They are graphical codes you can use to store data. &lt;/p&gt;

&lt;p&gt;You can quack QR codes with &lt;a href="https://duckduckgo.com/?q=QR+hello+world&amp;amp;t=h_&amp;amp;ia=answer" rel="noopener noreferrer"&gt;duckduckgo&lt;/a&gt;. Type "QR hello world" for it to generate a QR code containing "hello world". But did you know you can do it from 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%2Fproxy.duckduckgo.com%2Fiu%2F%3Fu%3Dhttps%253A%252F%252Fmedia.tenor.com%252Fimages%252F8c4cb0ca7303aa791c4458d496379b07%252Ftenor.gif%26f%3D1" 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%2Fproxy.duckduckgo.com%2Fiu%2F%3Fu%3Dhttps%253A%252F%252Fmedia.tenor.com%252Fimages%252F8c4cb0ca7303aa791c4458d496379b07%252Ftenor.gif%26f%3D1"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  QR codes backup with Python
&lt;/h3&gt;

&lt;p&gt;We'll convert files in bulk to QR codes with &lt;a href="https://pythonprogramminglanguage.com/" rel="noopener noreferrer"&gt;Python programming&lt;/a&gt;. This guide is for Linux computers.&lt;/p&gt;

&lt;p&gt;Install zbar-tools and qrcode module&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo apt install zbar-tools
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Then you can convert all (.py) files in a directory to qr codes.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#!/usr/bin/python3
import qrcode
import glob

files = glob.glob("*.py")
for filename in files:
    data = ""
    with open(filename, 'r') as file:
            data = file.read()

    img = qrcode.make(data)
    img.save('qr-' + filename + '.png')
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;There's a limit to the file size, about 8 kilobytes. But for small files this actually works.&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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Ffujf4tzi2a4wyojko4yb.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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Ffujf4tzi2a4wyojko4yb.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This creates a QR code when running the program for each python file in the directory (*.py).&lt;/p&gt;

&lt;p&gt;You can decode a QR code with the command:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;zbarimg qr-qrfs.py.png
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Then you can print all your files on paper. If they files fit into the QR code that is.&lt;/p&gt;

&lt;p&gt;Related links:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://en.wikipedia.org/wiki/QR_code" rel="noopener noreferrer"&gt;QR code on wikipedia&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://linux.die.net/man/1/zbarimg" rel="noopener noreferrer"&gt;zbarimg program&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://pythonprogramminglanguage.com/" rel="noopener noreferrer"&gt;Learn Python&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>python</category>
    </item>
    <item>
      <title>Python pip, what's installed? </title>
      <dc:creator>petercour</dc:creator>
      <pubDate>Wed, 24 Jul 2019 14:26:45 +0000</pubDate>
      <link>https://dev.to/petercour/python-pip-what-s-installed-2dib</link>
      <guid>https://dev.to/petercour/python-pip-what-s-installed-2dib</guid>
      <description>&lt;p&gt;You probably use pip thousands of time if you are programming Python. &lt;a href="https://pypi.org/project/pip/" rel="noopener noreferrer"&gt;pip is the package installer&lt;/a&gt; for &lt;a href="https://pythonbasics.org" rel="noopener noreferrer"&gt;Python&lt;/a&gt;. You can use pip to install packages from the Python Package Index and other indexes.&lt;/p&gt;

&lt;p&gt;When creating a Python project, you do so in a virtual environment (or maybe you don't?). &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%2Fproxy.duckduckgo.com%2Fiu%2F%3Fu%3Dhttps%253A%252F%252Fmedia.giphy.com%252Fmedia%252FWwIe4phY9crpm%252Fgiphy.gif%26f%3D1" 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%2Fproxy.duckduckgo.com%2Fiu%2F%3Fu%3Dhttps%253A%252F%252Fmedia.giphy.com%252Fmedia%252FWwIe4phY9crpm%252Fgiphy.gif%26f%3D1"&gt;&lt;/a&gt;&lt;/p&gt;

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

&lt;/div&gt;

&lt;p&gt;Then you install packages for your project. So how do you know what all the installed modules are?&lt;/p&gt;

&lt;p&gt;Easy, there's a command &lt;/p&gt;

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

&lt;/div&gt;

&lt;p&gt;So if you want to know which version of a module you have, combine with grep.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;λ  ~  pip list | grep 'tensorflow'
tensorflow (1.14.0)
tensorflow-estimator (1.14.0)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;If you are using Ubuntu Linux or similar, you may have the odd situation in which you have both pip, pip3, python and python3 installed. Did the Ubuntu creators have some evil plan?&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%2Fproxy.duckduckgo.com%2Fiu%2F%3Fu%3Dhttps%253A%252F%252Fmedia.giphy.com%252Fmedia%252Fl0HluOGg5nXebqJwI%252Fgiphy.gif%26f%3D1" 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%2Fproxy.duckduckgo.com%2Fiu%2F%3Fu%3Dhttps%253A%252F%252Fmedia.giphy.com%252Fmedia%252Fl0HluOGg5nXebqJwI%252Fgiphy.gif%26f%3D1"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In that case, just add 3 after the pip command. For other operating systems, you can just use Python and pip.&lt;/p&gt;

&lt;p&gt;Related links:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://pypi.org/project/pip/" rel="noopener noreferrer"&gt;Python pip, package manager&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://pypi.org/" rel="noopener noreferrer"&gt;Python package repository&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://pythonbasics.org" rel="noopener noreferrer"&gt;Learn Python&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://pythonbasics.org/exercises/" rel="noopener noreferrer"&gt;Python exercises&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>python</category>
      <category>programming</category>
    </item>
    <item>
      <title>Call DLL functions from Python</title>
      <dc:creator>petercour</dc:creator>
      <pubDate>Tue, 23 Jul 2019 18:26:16 +0000</pubDate>
      <link>https://dev.to/petercour/call-dll-functions-from-python-jo4</link>
      <guid>https://dev.to/petercour/call-dll-functions-from-python-jo4</guid>
      <description>&lt;p&gt;Do you hav experience with C programming? &lt;/p&gt;

&lt;p&gt;You can call C functions from &lt;a href="https://pythonprogramminglanguage.com/" rel="noopener noreferrer"&gt;Python&lt;/a&gt;, with ctypes. What is ctypes?&lt;/p&gt;

&lt;p&gt;&lt;em&gt;ctypes is a foreign function library for Python. It provides C compatible data types, and allowscalling functions in DLLs or shared libraries. It can be used to wrap these libraries in pure Python.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;This how to do it in Python 2.x (if you still have that):&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#!/usr/bin/python
from ctypes import *

libc = cdll.LoadLibrary("/lib/x86_64-linux-gnu/libc.so.6")
printf = libc.printf
printf("hello world\n")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;For Python 3.x programs (yes the difference is one character)&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#!/usr/bin/python3
from ctypes import *

libc = cdll.LoadLibrary("/lib/x86_64-linux-gnu/libc.so.6")
printf = libc.printf
printf(b"hello world\n")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Make sure the path to your shared library (libc.so.6) is right. &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%2Fproxy.duckduckgo.com%2Fiu%2F%3Fu%3Dhttp%253A%252F%252Fsocialnewsdaily.com%252Fwp-content%252Fuploads%252F2016%252F07%252Funnbgkdbmsszmazgxkmr.jpg%26f%3D1" 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%2Fproxy.duckduckgo.com%2Fiu%2F%3Fu%3Dhttp%253A%252F%252Fsocialnewsdaily.com%252Fwp-content%252Fuploads%252F2016%252F07%252Funnbgkdbmsszmazgxkmr.jpg%26f%3D1"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Chances are it's on another location. On Windows or Mac its different path and name. Otherwise it's very basic, and this should work for any C library.&lt;/p&gt;

&lt;p&gt;Related links:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://stackoverflow.com/questions/5081875/ctypes-beginner#5082294" rel="noopener noreferrer"&gt;Ctypes beginner example (Python+C)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.python.org/2/library/ctypes.html" rel="noopener noreferrer"&gt;Ctypes documentation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://pythonprogramminglanguage.com/" rel="noopener noreferrer"&gt;Learn Python programming&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>python</category>
      <category>c</category>
    </item>
    <item>
      <title>Generate QR codes in Python</title>
      <dc:creator>petercour</dc:creator>
      <pubDate>Tue, 23 Jul 2019 16:43:32 +0000</pubDate>
      <link>https://dev.to/petercour/generate-qr-codes-in-python-2da2</link>
      <guid>https://dev.to/petercour/generate-qr-codes-in-python-2da2</guid>
      <description>&lt;p&gt;QR code a type of matrix barcode first designed in 1994 for the automotive industry in Japan. These days it's used in many places like banking, cryptocurrency, advertisements and more.&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%2Fproxy.duckduckgo.com%2Fiu%2F%3Fu%3Dhttps%253A%252F%252Fentrackr.com%252Fwp-content%252Fuploads%252F2018%252F03%252FBharat-qr-app-image_2.gif%26f%3D1" 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%2Fproxy.duckduckgo.com%2Fiu%2F%3Fu%3Dhttps%253A%252F%252Fentrackr.com%252Fwp-content%252Fuploads%252F2018%252F03%252FBharat-qr-app-image_2.gif%26f%3D1"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Did you know you can generate these codes with Python? You should know the &lt;a href="https://pythonbasics.org" rel="noopener noreferrer"&gt;Python programming language&lt;/a&gt;. But even without to much practice, you can generate them.&lt;/p&gt;

&lt;p&gt;Install the qrcode module&lt;/p&gt;

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

&lt;/div&gt;

&lt;p&gt;Then you can load it in Python&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#!/usr/bin/python3
import qrcode
img = qrcode.make('hello world')
img.save('test.png')
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;This will output the QR code as an image (test.png).&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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fzldv7y8ovcvdt1uhxmk4.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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fzldv7y8ovcvdt1uhxmk4.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So it's that easy. How much data can you store on a QR code?&lt;/p&gt;

&lt;p&gt;According to &lt;a href="https://stackoverflow.com/questions/11065415/how-much-data-information-can-we-save-store-in-a-qr-code" rel="noopener noreferrer"&gt;stackoverflow&lt;/a&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;QR codes have three parameters: 
Datatype, size (number of 'pixels') and error correction level. 
How much information can be stored there also depends on these   
parameters. 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;ul&gt;
&lt;li&gt;Numeric only Max. 7,089 characters&lt;/li&gt;
&lt;li&gt;Alphanumeric Max. 4,296 characters&lt;/li&gt;
&lt;li&gt;Binary/byte Max. 2,953 characters (8-bit bytes)&lt;/li&gt;
&lt;/ul&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%2Fproxy.duckduckgo.com%2Fiu%2F%3Fu%3Dhttps%253A%252F%252Fmedia.giphy.com%252Fmedia%252Fqr8EicESfLSCY%252Fgiphy.gif%26f%3D1" 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%2Fproxy.duckduckgo.com%2Fiu%2F%3Fu%3Dhttps%253A%252F%252Fmedia.giphy.com%252Fmedia%252Fqr8EicESfLSCY%252Fgiphy.gif%26f%3D1"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You may be able to zip your data and bypass this limit to some extend.&lt;/p&gt;

&lt;p&gt;Related links:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://en.wikipedia.org/wiki/QR_code" rel="noopener noreferrer"&gt;QR codes on Wikipedia&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://pythonbasics.org/" rel="noopener noreferrer"&gt;Learn Python&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://pythonbasics.org/exercises/" rel="noopener noreferrer"&gt;Python exercises&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>python</category>
      <category>qr</category>
    </item>
    <item>
      <title>Fuzzywuzzy and Python</title>
      <dc:creator>petercour</dc:creator>
      <pubDate>Tue, 23 Jul 2019 13:05:13 +0000</pubDate>
      <link>https://dev.to/petercour/fuzzywuzzy-and-python-2m6</link>
      <guid>https://dev.to/petercour/fuzzywuzzy-and-python-2m6</guid>
      <description>&lt;p&gt;What's fuzzywuzzy? &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--K56IozGL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://proxy.duckduckgo.com/iu/%3Fu%3Dhttps%253A%252F%252Fmedia.giphy.com%252Fmedia%252F3XXcyZlvqo9tm%252Fgiphy.gif%26f%3D1" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--K56IozGL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://proxy.duckduckgo.com/iu/%3Fu%3Dhttps%253A%252F%252Fmedia.giphy.com%252Fmedia%252F3XXcyZlvqo9tm%252Fgiphy.gif%26f%3D1"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It's a string matching module. A string is &lt;a href="https://pythonprogramminglanguage.com/variables/"&gt;variable&lt;/a&gt; that can store (and modify) text. It uses &lt;a href="https://en.wikipedia.org/wiki/Levenshtein_distance"&gt;Levenshtein Distance&lt;/a&gt; to calculate the differences between sequences in a simple-to-use package.&lt;/p&gt;

&lt;p&gt;Fuzzy string matching like a boss.&lt;br&gt;
How to get started? First you should know &lt;a href="https://pythonprogramminglanguage.com/"&gt;Python programming&lt;/a&gt;. &lt;/p&gt;

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

&lt;p&gt;Then you can use it like this:&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#!/usr/bin/python3
from fuzzywuzzy import fuzz
from fuzzywuzzy import process

r = fuzz.ratio("this is a test", "this is a test!")
print(r)

r = fuzz.ratio("fuzzy wuzzy was a bear", "wuzzy fuzzy was a bear")
print(r)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;This outputs the ratio:&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;97
91
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;You can run this from the interpreter:&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; fuzz.ratio("this is a test", "this is a test!")
    97
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Another example of fuzzywuzzy:&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; from fuzzywuzzy import fuzz
&amp;gt;&amp;gt;&amp;gt; fuzz.ratio("this is a test","a test this is")
50
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Related links:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://github.com/seatgeek/fuzzywuzzy"&gt;Fuzzywuzzy module&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://pythonprogramminglanguage.com/"&gt;Learn Python&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

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