<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Besmire Thaqi on Medium]]></title>
        <description><![CDATA[Stories by Besmire Thaqi on Medium]]></description>
        <link>https://medium.com/@thaqibsm?source=rss-f3023fd723c0------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*GwX5_zQX-KK1pZYx4l6r4w.png</url>
            <title>Stories by Besmire Thaqi on Medium</title>
            <link>https://medium.com/@thaqibsm?source=rss-f3023fd723c0------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 18:13:54 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@thaqibsm/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Create a Blog with Django]]></title>
            <link>https://medium.com/geekculture/create-a-blog-with-django-60f529f1d8b6?source=rss-f3023fd723c0------2</link>
            <guid isPermaLink="false">https://medium.com/p/60f529f1d8b6</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[django]]></category>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[blog]]></category>
            <category><![CDATA[coding]]></category>
            <dc:creator><![CDATA[Besmire Thaqi]]></dc:creator>
            <pubDate>Mon, 22 Mar 2021 16:47:59 GMT</pubDate>
            <atom:updated>2021-03-24T23:32:49.352Z</atom:updated>
            <content:encoded><![CDATA[<h4>A step-by-step guide to create a Blog from scratch with Python and Django.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IoqhqksPyD4jW8UezzuXdQ.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@kaitlynbaker?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Kaitlyn Baker</a> on <a href="https://medium.com/collections/9795850/tech?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>Creating a personalized blog site from scratch is simpler than it seems. Especially when using specific frameworks which provide built-in features that are ready to use. Django is an awesome framework for such cases.</p><h3>Creating a Django app</h3><p>In this tutorial, all the necessary steps to follow for developing and maintaining the site are covered and briefly explained in the right order.</p><h4>1.0 Initial setup</h4><p>Assuming that Python3 is already installed, create a directory as a starting point:</p><pre># create a dir<br>mkdir djangoblog</pre><pre># navigate to dir<br>cd djangoblog</pre><h4>1.1 Virtual environment</h4><p>Creating a virtual environment is super simple. Try the command below:</p><pre># python3 -m venv &lt;name&gt;<br>python3 -m venv <strong>venv</strong></pre><p>In this way, there is virtual environment created and named as <strong>venv</strong>. Now, let’s activate it:</p><pre># source &lt;name&gt;/bin/activate<br>source <strong>venv</strong>/bin/activate</pre><p>Inside the virtual environment, there is the latest version of Python (in this case: 3.9) and latest version of pip (in this case: 21.0.1). Then, let’s install Django (by default is the latest version, in this case: 3.1.7):</p><pre># pip install &lt;package-name&gt;<br>pip install django</pre><h4>1.2 Project setup (1)</h4><p>After creating and activating the virtual environment, the next step is to create a directory and create a Django project there:</p><pre># create a dir<br>mkdir <strong>mysite</strong></pre><pre># navigate to dir<br>cd <strong>mysite</strong></pre><pre># create a django project<br>django-admin startproject <strong>mysite</strong></pre><p>Now, the structure of the directory is generated as shown below:</p><pre><em>| — mysite<br>| | — __init__.py<br>| | — asgi.py<br>| | — settings.py<br>| | — urls.py<br>| | — wsgi.py<br>| — manage.py</em></pre><p>But, what do these files mean?</p><ul><li><strong>__init__.py</strong> → A blank Python script which indicates to the Python interpreter that this directory is actually a Python package. It allows Python packages to be imported from the directories.</li><li><strong>asgi.py</strong> → Provides a standard interface between async-capable Python web servers, frameworks, and applications.</li><li><strong>settings.py</strong> → A file that contains the configuration of the Django project.</li><li><strong>urls.py</strong> → A file that contains URL patterns for the Django project.</li><li><strong>wsgi.py</strong> → A file that contains WSGI configuration properties of the Django project. It’s basically a Python script that is used to run the development server and to help deploying to a production environment.</li><li><strong>manage.py</strong> → A command line utility and allows to interact with the Django project in many ways.</li></ul><p>First, it may be confusing that there are two directories with the same name. However, the name of the main directory can still be changed with whatever name preferred.</p><p>On the other side, the second-level directory name is hardcoded in some of Django specific files, therefore; it is not recommended to change its name.</p><h4><strong>1.3 Run the project</strong></h4><p>Django comes with a built-in web server for development. To run the project, simply navigate where the <em>manage.py</em> file is located and try the commands:</p><pre># default run in <a href="http://127.0.0.1:8000/">http://127.0.0.1:8000/</a><br>python manage.py runserver</pre><pre># use another port in localhost<br>python manage.py runserver 2000</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*obATOk4krziDlkV7VLAe6w.png" /></figure><h4>1.4 Project setup (2)</h4><p>Now that a Django project has been created, the next step is to create a Django app. Let’s navigate where the <em>manage.py</em> file is located and start an app:</p><pre># python manage.py startapp &lt;name&gt;<br>python manage.py startapp <strong>blog</strong></pre><p>The app has been created and named as <strong>blog</strong>. Notice that new files are generated within the director and the current structure looks like this:</p><pre><em>|— db.sqlite3<br>|— mysite<br>| |— __init__.py<br>| |— asgi.py<br>| |— settings.py<br>| |— urls.py<br>| |— wsgi.py<br>|— manage.py<br>|— blog<br>| |— __init__.py<br>| |— admin.py<br>| |— apps.py<br>| |— migrations<br>| |— models.py<br>| |— tests.py<br>| |— views.py</em></pre><p>After creating an app, Django needs to know that there is a new app in the project. To tell Django about this, check the settings file (<em>mysite/settings.py</em>). Here you will find the default installed apps:</p><pre>INSTALLED_APPS = [<br>&#39;django.contrib.admin&#39;,<br>&#39;django.contrib.auth&#39;,<br>&#39;django.contrib.contenttypes&#39;,<br>&#39;django.contrib.sessions&#39;,<br>&#39;django.contrib.messages&#39;,<br>&#39;django.contrib.staticfiles&#39;,<br>]</pre><p>And, here is where we add the new app as well:</p><pre>INSTALLED_APPS = [<br>&#39;django.contrib.admin&#39;,<br>&#39;django.contrib.auth&#39;,<br>&#39;django.contrib.contenttypes&#39;,<br>&#39;django.contrib.sessions&#39;,<br>&#39;django.contrib.messages&#39;,<br>&#39;django.contrib.staticfiles&#39;,<br>&#39;blog&#39;,<br>]</pre><h4>2.0 Database models</h4><p>As seen in the project structure above, there is an SQLite database generated in the Django project.</p><p>In Python, a model is a class that inherits from <em>django.db.models.Model</em>. Each attribute inside a model class represents a database field. First, since now there is an app created from steps mentioned above, there are also some database migrations created by default that we need to run:</p><pre>python manage.py migrate</pre><p>Assuming the initial migrations were executed successfully, let’s check an example of a table called <strong>Post </strong>and its fields:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b05d96c473cc8022731a8e69d841e1f8/href">https://medium.com/media/b05d96c473cc8022731a8e69d841e1f8/href</a></iframe><p>This model is a typical example of a blog post and what is usually needed and specified for one. In the beginning, the <strong>models</strong> and the <strong>User</strong> default model from Django is imported. There is a <strong>title</strong><em>, </em>a<em> </em><strong>slug</strong>, the<strong> author</strong> and the <strong>content</strong> of course. The <strong>author</strong> is a foreign key to the default Django model <strong>User</strong>. The <strong>status</strong> is to specify that the post by default is just a <strong>draft</strong>, and then it will be <strong>published</strong>.</p><p>There are two more specific fields called <strong>created_at</strong> and <strong>updated_at</strong>. These will be automatically updated with the specific <strong>date+time</strong> when an instance is added or updated in the database table. The <strong>ordering</strong> of objects created will be from last to first.</p><p>Note that the<strong> __str__()</strong> method is the human readable representation of the object. This will be used by Django in many places, such as in the <em>admin</em> site.</p><p>To create a new table in the database, first we need to generate a migration file and then execute this migration:</p><pre># create the migration file in migrations dir<br>python manage.py makemigrations</pre><pre># migrate changes to the db<br>python manage.py migrate</pre><h4>2.1 Admin built-in interface</h4><p>Django comes with a built-in admin interface. At this point, what’s left to do is to create a superuser and login to the admin panel:</p><pre>python manage.py createsuperuser</pre><pre><em>Username (leave blank to use &#39;&lt;username&gt;&#39;): &lt;provide username&gt;<br>Email address: &lt;provide email address&gt;<br>Password: &lt;provide password&gt;<br>Password (again): &lt;provide password again&gt;<br>Superuser created successfully.</em></pre><p>When executing the command, a username, email and password is required. Afterwards, let’s re-run the development server:</p><pre># default run in <a href="http://127.0.0.1:8000/">http://127.0.0.1:8000/</a><br>python manage.py runserver</pre><p>To access the built-in admin interface, try<strong> </strong><a href="http://127.0.0.1:8000/admin/"><strong><em>http://127.0.0.1:8000/admin/</em></strong><em>.</em></a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HBbZhFvvejYV_tHHVii-uQ.png" /></figure><p>After login, only <strong>Groups</strong> and <strong>Users</strong> from Django authentication model are visible as seen in the picture below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jiZjD4erkko5pPJ16xrzig.png" /></figure><p>In order to also see the <strong>Post </strong>model created from the example above, this should be included in the <em>admin.py</em> file of the blog app (<em>blog/admin.py</em>):</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a5e3cc378ac50cd2923badfc5468cafa/href">https://medium.com/media/a5e3cc378ac50cd2923badfc5468cafa/href</a></iframe><p>Based on the previous piece of code, the <strong>title</strong>, <strong>slug</strong> and <strong>status</strong> will be visible in the list of posts. It can be filtered by the <strong>status</strong> defined, and searching is possible by <strong>title</strong> or <strong>content</strong>. The <strong>Post</strong> model will be available in the interface:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fUR68cvhWc2w4rJQtIkb6w.png" /></figure><p>Note that a few blog post examples are added as shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OlxyUle6Qn6xj-uBT1dezg.png" /></figure><h4>3.0 Views</h4><p>A view is basically a function that receives a web request and returns a web response. The goal is to create views, create HTML template for the data returned by these views, and map them with specific URLs.</p><p>Let’s dig into more code and update file (<em>blog/views.py)</em>:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/397d237774f48043c8036c8f5e16e33e/href">https://medium.com/media/397d237774f48043c8036c8f5e16e33e/href</a></iframe><h4>3.1 URL Patterns</h4><p>When a user makes a request to the page, the Django controller checks the URLs to return the right view. Firstly, let’s a create a file in the <em>mysite/blog</em> directory named <em>urls.py</em>, which includes the code as shown below:</p><pre>from . import views<br>from django.urls import path</pre><pre>urlpatterns = [<br>    path(&#39;&#39;, views.PostList.as_view(), name=&#39;home&#39;),<br>    path(&#39;&lt;slug:slug&gt;/&#39;, views.PostDetail.as_view(),  name=&#39;post_detail&#39;),<br>]</pre><p>Then, the URLs from the blog needs to be imported in the URLs file of mysite directory (<em>mysite/urls.py</em>):</p><pre>from django.contrib import admin<br>from django.urls import path, include</pre><pre>urlpatterns = [<br>    path(&#39;admin/&#39;, admin.site.urls),<br>    path(&#39;&#39;, include(&#39;blog.urls&#39;)),<br>]</pre><h4>3.2 Templates</h4><p>Templates for views are created by using HTML, CSS and Django template language. First, let’s create a directory for templates in the base directory.</p><p>To use the templates, they need to be configured in the settings first:</p><pre># Added template directory in settings.py<br>TEMPLATES_DIRS = os.path.join(BASE_DIR,&#39;templates&#39;)</pre><pre>...</pre><pre>TEMPLATES = [{<br>    &#39;BACKEND&#39;: &#39;django.template.backends.django.DjangoTemplates&#39;,<br>    &#39;DIRS&#39;: [TEMPLATES_DIRS], # Template directory added here<br>    &#39;APP_DIRS&#39;: True,<br>    &#39;OPTIONS&#39;: {<br>        &#39;context_processors&#39;: [<br>        &#39;django.template.context_processors.debug&#39;,<br>        &#39;django.template.context_processors.request&#39;,<br>        &#39;django.contrib.auth.context_processors.auth&#39;,<br>        &#39;django.contrib.messages.context_processors.messages&#39;,<br>        ],<br>    },<br>},]</pre><p>Then, let’s have four different (*.html) files:</p><ul><li><strong>base.html </strong>→ The main template, the “skeleton” of the templates. It includes the header, navigation bar, the content &amp; the footer.</li><li><strong>index.html </strong>→ Extends the<em> base.html</em> template, using Django template language. It contains the blog entries in the main page, using the template of <em>post_detail.html</em>. It also includes the<strong> </strong><em>sidebar.html</em><strong> </strong>file.</li><li><strong>sidebar.html </strong>→ A small sidebar added in the main page.</li><li><strong>post_detail.html </strong>→ The detailed view of the blog post.</li></ul><p>Let’s check how the files mentioned from above look like:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9e38c94f3b238ce32fb2c62520ba2e0e/href">https://medium.com/media/9e38c94f3b238ce32fb2c62520ba2e0e/href</a></iframe><p>Small example and explanation of using DTL in<strong> index.html</strong> file:</p><pre># Extending an HTML template using Django template language<br>{% extends &quot;base.html&quot; %}</pre><pre>...</pre><pre># Including an HTML template using DTL<br>{% include &quot;sidebar.html&quot; %}</pre><pre>...</pre><pre># Iterating through the objects inserted in the db table &quot;Post&quot;<br># List &quot;post_list&quot; is available because of inheriting from ListView<br>{% for post in post_list %} # for post in &quot;Post&quot; db table<br>    {% post.title %}  # get the title of post</pre><blockquote>Note: For more details about Django template language, visit <a href="https://docs.djangoproject.com/en/3.1/ref/templates/language/">here</a>.</blockquote><p>Lastly, the structure of the project looks similar like the example below:</p><pre><em>|— db.sqlite3<br>|— mysite<br>| |— __init__.py<br>| |— asgi.py<br>| |— settings.py<br>| |— urls.py<br>| |— wsgi.py<br>|— manage.py<br>|— blog<br>| |— __init__.py<br>| |— admin.py<br>| |— apps.py<br>| |— migrations<br>| |— models.py<br>| |— tests.py<br>| |— views.py<br>| - templates<br>| |- base.html<br>| |- index.html<br>| |- post_detail.html<br>| |- sidebar.html</em></pre><h3>Congratulations! 🎉</h3><p>Assuming all the steps mentioned in this post are followed correctly, the personal blog is now ready to use and looks like in the pictures shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*A0JSfnueB5gVI7tK1onFIg.png" /><figcaption>Blog’s main page</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*t-dH8RcTqSyd1BW7H8M_7A.png" /><figcaption>Detailed view of a blog post</figcaption></figure><p>In addition, feel free to check the source code from my git repo:</p><p><a href="https://github.com/bthaqi/django-blog">bthaqi/django-blog</a></p><h3>Want to learn more?</h3><p>Some great sources for Django documentation and tutorials, which I’m also inspired by, are mentioned below:</p><ul><li><a href="https://docs.djangoproject.com/en/3.1/">https://docs.djangoproject.com/en/3.1/intro/tutorial01/</a></li><li><a href="https://djangocentral.com/django/">https://djangocentral.com/django/</a></li><li><a href="https://www.fullstackpython.com/django.html">https://www.fullstackpython.com/django.html</a></li></ul><blockquote>Note: My all-time favorite book about Django 🍨</blockquote><p><a href="https://g.co/kgs/MxyA4c">Two Scoops of Django 1.11: Best Practices for the Django Web Framework - Google Search</a></p><h3>A short recap</h3><p>All the necessary steps to create a personal blog from scratch with Python3 and Django3 are covered in this short tutorial.</p><p>First, it explains what needs to be installed, and how to create a Django3 app. A short description is written for the structure of a Django app, what files does the app contain and what are their purposes.</p><p>Then, proceeding with the database models, migrations and admin built-in interface until the brief explanation of views and rendered templates in Django.</p><p>Assuming all the steps are followed in the correct way, the personal blog is ready to use and be customized in <em>your own preferred way</em>!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=60f529f1d8b6" width="1" height="1" alt=""><hr><p><a href="https://medium.com/geekculture/create-a-blog-with-django-60f529f1d8b6">Create a Blog with Django</a> was originally published in <a href="https://medium.com/geekculture">Geek Culture</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Finite State Machines With Django]]></title>
            <link>https://medium.com/swlh/finite-state-machines-with-django-b44198e1ca13?source=rss-f3023fd723c0------2</link>
            <guid isPermaLink="false">https://medium.com/p/b44198e1ca13</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[development]]></category>
            <category><![CDATA[django]]></category>
            <category><![CDATA[fsm]]></category>
            <dc:creator><![CDATA[Besmire Thaqi]]></dc:creator>
            <pubDate>Mon, 19 Oct 2020 16:50:21 GMT</pubDate>
            <atom:updated>2020-11-10T08:48:30.447Z</atom:updated>
            <content:encoded><![CDATA[<h4>How to define finite state machines for models using Django</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CYUpta_wVMM23sbE1xdidQ.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@veverkolog?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Dušan Veverkolog</a> on <a href="https://unsplash.com/s/photos/traffic-lights?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>In software engineering, we often need to design a model of our application’s behavior. Finite state machines represent a design pattern that is widely used for this topic.</p><p>Before jumping into any example or piece of code, let’s explain what does a finite state machine mean.</p><h4>What are finite state machines?</h4><p>A finite state machine is simply a model of computation to simulate a sequential logic. The model which we define the finite state machines for, can be in exactly one of the finite number of states at a time.</p><p>The state (or status) can change from one to another in response to some external inputs. This process is also known as a transition.</p><h4>Traffic lights as finite state machines 🚦</h4><p>This is the simplest example to use and understand because it has three states.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/495/1*9u1d2dk6P2Rraq29k7nXew.png" /></figure><p>The default (or the first) state is the green light. The state changes allowed are as followed:</p><ul><li>Green → Yellow</li><li>Yellow → Red</li><li>Red → Green</li></ul><p>In Django, these finite state machines and transitions can be defined by specifying the source and the target of the transition. Let’s dig into code!</p><h4>The Django FSM</h4><p>The library is called “django-fsm” and it’s very simple to use. First, make sure to install it:</p><pre>pip install django-fsm</pre><p>The state field has to be an FSM field with a default value. Therefore; the <strong>FSMField</strong> is imported. In our case, we have the green light as the default one:</p><pre><em>from</em> django_fsm <em>import</em> FSMField, transition</pre><pre>class TrafficLight(models.Model):<br>    state = FSMField(default=&quot;green&quot;, protected=True)</pre><p>The attribute <strong>protected=True</strong> prevents changing the state directly, as shown in the example below:</p><pre>model = TrafficLight()<br>model.state = &quot;red&quot; # raises AttributeError</pre><p>Additionally; the transitions need to be defined using the <strong>@transition</strong> as a decorator and specifying the FSM field we added above. Other variables that the decorator takes are for example the <strong>source</strong> and the <strong>target</strong>.</p><p>The <strong>source</strong> is the state from which the transition is allowed to happen and the <strong>target </strong>is the state to which the transition will happen:</p><pre>@transition(field=state, source=&quot;green&quot;, target=&quot;yellow&quot;)<br>def to_state_yellow(self):<br>    <em>return</em> &quot;Light switched to yellow!&quot;</pre><pre>@transition(field=state, source=&quot;yellow&quot;, target=&quot;red&quot;)<br>def to_state_red(self):<br>    <em>return</em> &quot;Light switched to red!&quot;</pre><pre>@transition(field=state, source=&quot;red&quot;, target=&quot;green&quot;)<br>def to_state_green(self):<br>    <em>return</em> &quot;Light switched to green!&quot;</pre><p>When these transitions are defined as shown in the example, it means that they are the only transitions allowed. Any other behavior is not allowed. For example, we don’t have a transition specified as “<strong>green</strong> → <strong>red”</strong>. In this case an exception will be thrown.</p><p>So far, our model looks something like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5a712e59c7e433a9d7a47baa14d75ab1/href">https://medium.com/media/5a712e59c7e433a9d7a47baa14d75ab1/href</a></iframe><p>Furthermore; let’s take a more advanced example with a ticketing system. There are tickets with different state machines and transitions defined like in the graph below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/601/1*RKBUj-DGvy2Yr__Z2LPmHw.png" /></figure><p>The ticket can be created, picked up, marked as failed or closed by a particular user.</p><blockquote>Notice that if a ticket is “<strong>in progress</strong>” state or in “<strong>failed</strong>” state, they can both transition to “<strong>closed</strong>” state. In this case we have two sources with the same target.</blockquote><p>The source parameter in the <strong>@transition</strong> decorator accepts an array to specify more than one state. This is how it looks code-wise:</p><pre>@transition(field=state, source=[&quot;in_progress&quot;, &quot;failed&quot;], target=&quot;closed&quot;)<br>def to_state_closed(self):<br>    pass</pre><p>Based on the transitions, this is how the model currently looks:</p><pre><em>from</em> django_fsm <em>import</em> FSMField, transition</pre><pre>class Ticket(models.Model):<br>    state = FSMField(default=&quot;created&quot;)<br>    <br>    ...</pre><pre>    @transition(field=state, source=&quot;created&quot;, target=&quot;in_progress&quot;)<br>    def to_state_in_progress(self):<br>        pass</pre><pre>    @transition(field=state, source=[&quot;in_progress&quot;, &quot;created&quot;],     target=&quot;failed&quot;)<br>    def to_state_failed(self):<br>        pass</pre><pre>    @transition(field=state, source=[&quot;in_progress&quot;, &quot;failed&quot;], target=&quot;closed&quot;)<br>    def to_state_closed(self):<br>        pass</pre><h4>What about logging? 🔍</h4><p>Now that the basic concept is clear regarding Django FSM, we want to add some logging for these transitions. This helps to add some description and track by whom the transition was made.</p><h4>The Django FSM logs</h4><p>There is another library supported for logs which has to be installed first:</p><pre>pip install django-fsm-log</pre><p>And then, also added in the Django apps:</p><pre>INSTALLED_APPS = (<br>    ...,<br>    &#39;django_fsm_log&#39;,<br>    ...,<br>)</pre><p>From this library, some decorators like <strong>fsm_log_by</strong> and <strong>fsm_log_description </strong>can be imported. These ones are added above the transition we want to use and also added as parameters in the method, like this:</p><pre>@fsm_log_by<br>@fsm_log_description<br>@transition(field=state, source=[&quot;in_progress&quot;, &quot;failed&quot;], target=&quot;closed&quot;)<br>def to_state_closed(self, by=None, description=None):<br>    pass</pre><p>The parameters can be updated in the method when calling the transition:</p><pre>ticket = Ticket.objects.create()<br>ticket.to_state_in_progress(by=some_account, description=&quot;Ticket has been updated&quot;)</pre><p>In the end, the model for ticket will look like shown in the code below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d4dc480903abe421698311949a71d544/href">https://medium.com/media/d4dc480903abe421698311949a71d544/href</a></iframe><p>We either want to see the logs by using ORM (1) or directly in the Django admin panel (2). Fortunately; they are both possible!</p><p>To view the logs (1) we can import and use the StateLog model from django_fsm_log:</p><pre>from django_fsm_log.models import StateLog</pre><pre># get all recorded logs<br>StateLog.objects.all()</pre><pre># get the first ticket<br>ticket = Ticket.objects.first()</pre><pre># use the &quot;for_&quot; manager method to get logs for the specific ticket<br>StateLog.objects.for_(ticket)</pre><p>Implementing logs to see them in Django admin (2):</p><pre>from django.contrib import admin<br>from django_fsm_log.admin import StateLogInline<br><br><br>@admin.register(FSMModel)<br>class TicketModelAdmin(admin.ModelAdmin):<br>    inlines = [StateLogInline]<br>    ...</pre><h4><strong>A short recap</strong></h4><p>A finite state machine is a model of computation that simulates a sequential logic. Changing from one state to another is known as a transition.</p><p>These transitions can be defined for a model in Django. The Django FSM libraries are used for implementing the states, transitions and the logging. More than one source state can be specified for the same target state.</p><p>Logs can be implemented to use with ORM or also view them in a cool table in the Django admin.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b44198e1ca13" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/finite-state-machines-with-django-b44198e1ca13">Finite State Machines With Django</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What you need to know about Docker]]></title>
            <link>https://faun.pub/what-you-need-to-know-about-docker-9a5072ae82c3?source=rss-f3023fd723c0------2</link>
            <guid isPermaLink="false">https://medium.com/p/9a5072ae82c3</guid>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[containers]]></category>
            <category><![CDATA[development]]></category>
            <category><![CDATA[environment]]></category>
            <dc:creator><![CDATA[Besmire Thaqi]]></dc:creator>
            <pubDate>Sun, 15 Sep 2019 21:34:53 GMT</pubDate>
            <atom:updated>2020-12-01T20:59:39.191Z</atom:updated>
            <content:encoded><![CDATA[<h4>The Docker ecosystem and how to start with it</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yBnbEFHUx6b5tuSxosHoJA.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@jme1007?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Jacob Meissner</a> on <a href="https://unsplash.com/s/photos/shipping-boat?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>Let’s start with the famous phrase <strong><em>“based on a true story”</em></strong>.</p><p>Working in a startup is messy. Lots of requirements, new features all the time, new tools and technologies to deal with. This means that you’re adding more complexity to your project.</p><p>The harder it is to set up your project, the worse for you and your colleagues. As my dear colleague would say: <em>“If we cannot start the project with one command, we’re in trouble”.</em></p><p>As developers with the same KISS <em>(Keep It Simple, Stupid)</em> principle, we want to simplify our current setup. Run everything in one command, or two, whatever.</p><p><strong>Docker to the rescue! </strong>🐳</p><p>The before-mentioned situation is one of the many reasons why you should learn about Docker and containers. These tools are the new way of running software and the new revolution of the software development cycle.</p><h4>What the fuss is all about</h4><p>A lot of big companies put trust in Docker for many reasons. Business-wise it is on budget, it offers security and it’s very compatible.</p><h4>Docker Ecosystem ♻️</h4><p>It contains docker file, images, containers, and volumes. Docker files are files with instructions to create images.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YSBCLWogmszFDmKkl9QtVA.png" /></figure><p>An image; like in old times, serves like a CD or USB with the tools, libraries you need to run your app. Images are with all the necessary things we need to run our app. If we want to run an image, we would deploy it in the container.</p><p>Containers can be created, destroyed, and created again anytime we want without losing anything. You can think of it as a VM but smaller and independent from your current OS.</p><p>If you need multiple containers, you also need multiple docker commands. Therefore; sometimes it’s hard to remember these commands. Thus; <strong>docker-compose </strong>allows us to use a <strong>.yml </strong>file, and this will run all docker commands you need.</p><p><em>You don’t need to remember parameters, just put them on the file!</em></p><h4><strong>Get started with Docker</strong></h4><p><em>Let’s get to know our steps to start with the Docker environment! </em>🌟</p><p><strong>1. Download and Install Docker</strong></p><p>Make sure to install a maintained version of Docker from <strong>Docker Community Edition (DE)</strong> or <strong>Enterprise Edition (EE)</strong>: <a href="https://docs.docker.com/install/">https://docs.docker.com/install/</a></p><p><strong>2. Test Docker Version and Installation</strong></p><p>Run the following command to check if you have a supported version:</p><pre><strong>docker --version</strong><br>Docker version 18.09.2, build 6247962</pre><p>Check more information regarding the installation:</p><pre><strong>docker info</strong><br>Containers: 0<br> Running: 0<br> Paused: 0<br> Stopped: 0<br>Images: 0<br>Server Version: 18.09.2<br>...</pre><p>Test that your installation was successful:</p><pre><strong>docker run myapp</strong><br>Unable to find image &#39;myapp:latest&#39; locally<br>docker: Error response from daemon: pull access denied for myapp, repository does not exist or may require &#39;docker login&#39;.<br>See &#39;docker run --help</pre><p><strong>3. Create the Dockerfile</strong></p><p>Let’s start by specifying the base image in the Dockerfile. In this case, we’re pulling from Python3 base image:</p><pre><em># Pull official base image<br></em>FROM python:3</pre><p>The next step is writing commands for copying the files and installing the dependencies and we set a working directory to copy all the files of our app:</p><pre>RUN mkdir /myapp<br>WORKDIR /myapp<br>COPY requirements.txt /myapp/<br>RUN pip install -r requirements.txt<br>COPY . /myapp/</pre><p><strong>4. Commands Cheat Sheet</strong></p><pre><em>## List docker commands</em><br><strong>docker</strong></pre><pre><em>## List docker images</em><br><strong>docker image ls</strong></pre><pre><em>## List docker containers (currently running, all)<br></em><strong>docker container ls<br>docker container ls --all</strong></pre><pre><em>## Build docker images from Dockerfile, docker-compose.yml</em><br><strong>docker-compose up -d</strong></pre><pre><em>## Run docker image</em><br><strong>docker run &lt;my-app&gt;</strong></pre><pre><em>## Login with docker credentials</em><br><strong>docker login</strong></pre><pre><em>## Remove a docker image</em><br><strong>docker image rm &lt;image id&gt;</strong></pre><pre><em>## Remove a docker container</em><br><strong>docker container rm &lt;hash&gt;</strong></pre><pre><em>## Stop, kill a docker container</em><br><strong>docker container stop &lt;hash&gt;<br>docker container kill &lt;hash&gt;</strong></pre><h4>A short recap</h4><p>Docker is a new technology that allows development teams to build and manage secure apps. A docker container can be seen as a computer in your computer. It makes your app independent from your current OS.</p><p>Most importantly, this technology is open source!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/727/0*Piks8Tu6xUYpF4DU" /></figure><p>👋 <a href="https://faun.dev/join"><strong>Join FAUN today and receive similar stories each week in your inbox!</strong></a><strong> </strong>️ <strong>Get your weekly dose of the must-read tech stories, news, and tutorials.</strong></p><p><strong>Follow us on </strong><a href="https://twitter.com/joinfaun"><strong>Twitter</strong></a><strong> </strong>🐦<strong> and </strong><a href="https://www.facebook.com/faun.dev/"><strong>Facebook</strong></a><strong> </strong>👥<strong> and </strong><a href="https://instagram.com/fauncommunity/"><strong>Instagram</strong></a><strong> </strong>📷 <strong>and join our </strong><a href="https://www.facebook.com/groups/364904580892967/"><strong>Facebook</strong></a><strong> and </strong><a href="https://www.linkedin.com/company/faundev"><strong>Linkedin</strong></a><strong> Groups </strong>💬</p><figure><a href="https://www.faun.dev/join?utm_source=medium.com/faun&amp;utm_medium=medium&amp;utm_campaign=faunmediumbanner"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_cT0_laE4iPcqW1qrbstAg.gif" /></a></figure><h4>If this post was helpful, please click the clap 👏 button below a few times to show your support for the author! ⬇</h4><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9a5072ae82c3" width="1" height="1" alt=""><hr><p><a href="https://faun.pub/what-you-need-to-know-about-docker-9a5072ae82c3">What you need to know about Docker</a> was originally published in <a href="https://faun.pub/">FAUN.dev() 🐾</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Data Science with Python]]></title>
            <link>https://medium.com/thaqibsm/data-science-with-python-882af047e332?source=rss-f3023fd723c0------2</link>
            <guid isPermaLink="false">https://medium.com/p/882af047e332</guid>
            <category><![CDATA[data-analysis]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[data-scientist]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[big-data]]></category>
            <dc:creator><![CDATA[Besmire Thaqi]]></dc:creator>
            <pubDate>Wed, 11 Jul 2018 16:13:35 GMT</pubDate>
            <atom:updated>2020-10-28T12:53:19.382Z</atom:updated>
            <content:encoded><![CDATA[<h4>An overview of Data Science with Python from scratch</h4><h4>What is Data Science?</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/891/1*JrfzrDHoH7WfwdpyKxQeIA.png" /><figcaption>Data Science explained with a Venn Diagram [1]</figcaption></figure><p>Data Science is a field that includes data cleansing, preparation and analysis. It is a combination between statistics, mathematics, programming and problem-solving. Machine Learning and Artificial Intelligence are often incorporated when working in this area. Please refer to the picture shown above in order to understand better about what Data Science consists of!</p><h4><strong>What does a Data Scientist do?</strong></h4><blockquote>Did you know? Harvard calls “Data Scientist” as the sexiest job of the 21st century! (Check <a href="https://hbr.org/2012/10/data-scientist-the-sexiest-job-of-the-21st-century">here</a>.)</blockquote><p>As a Data Scientist, you work with structured and unstructured data. You determine whether the data sets are correct and accurate to use for further processes. Working with data sets means cleaning, validating, verifying them. This way, you use different algorithms or machine learning techniques to do analysis in the best way possible you can.</p><h4>Programming Languages and Libraries that Data Scientists use</h4><p>Two main programming languages that are used for this field are <strong>Python</strong> and <strong>R programming language</strong>. They have a lot of libraries to use for data analysis. For instance, in <strong>Python </strong>you have libraries like <a href="http://www.numpy.org/">NumPy</a>, <a href="https://pandas.pydata.org/">Pandas</a>, <a href="https://matplotlib.org/">Matplotlib, </a><a href="http://scikit-learn.org/stable/">Scikit-learn</a>, <a href="https://www.scipy.org/">SciPy</a>, <a href="https://www.nltk.org/">NLTK</a>, etc. for scientific computing.</p><p><strong>NumPy </strong>→ is used for multidimensional arrays and matrices. You can apply mathematical operations in the whole data set without using loops.</p><p><strong>Pandas </strong>→ is used to make the process of data analysis easier. You can create data frames and structure your data set.</p><p><strong>Matplotlib </strong>→ is used for data visualization. You can create histograms, pie charts, line graphs and lots of other professional grade figures.</p><p><strong>Scikit-learn</strong> → provides a lot of machine learning algorithms to use for your data sets. It is built on SciPy.</p><p><strong>SciPy</strong> → provides fast N-dimensional array manipulations. It has different modules like optimization, linear algebra, integration and other stuff related to Data Science.</p><p><strong>NLTK</strong> → is used to build platforms to interact with human language data. You can use it to work in computational linguistics.</p><p>Libraries mentioned above are only some of the most used ones (developed in Python), but there are a lot more that Python has to offer in this field.</p><h4>Data Science vs. Data Analytics vs. Big Data</h4><p>Often, these terms are being confused with each other. You can understand the differences better by the picture shown below with great details about each field.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/688/1*QmfpzkJ0P5XbzEKHbXy2kQ.png" /><figcaption>Differences between Data Science, Big Data and Data Analytics [2]</figcaption></figure><p>And if you were wondering, yes, it’s one of the most high-paid fields!</p><h4>Start learning Python and become a Data Scientist</h4><p>If you are new to this field and you want to start a real journey, I would strongly recommend to start learning basics with Python and then continue to more advanced programming with Data Science libraries developed in Python.</p><p>If you need more information about how to start with Python (isntallation, coding, IDEs, editors, etc) please check my story “<a href="https://medium.com/thaqibsm/introduction-to-python-51203ac160e4">Introduction to Python</a>”.</p><p>Also, I found it really helpful to get to know Data Science through <a href="https://www.datacamp.com/">DataCamp</a> courses, check them out!</p><p><em>References:</em></p><p><em>[1]. Python Data Science Handbook by Jake VanderPlas, 2017, pg. 11<br>[2]. Simple Learn Platform, Data Science vs. Big Data vs. Data Analytics article by Avantika Monnappa, 2018</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=882af047e332" width="1" height="1" alt=""><hr><p><a href="https://medium.com/thaqibsm/data-science-with-python-882af047e332">Data Science with Python</a> was originally published in <a href="https://medium.com/thaqibsm">Girl and the duck</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Introduction to Python]]></title>
            <link>https://medium.com/python-pandemonium/introduction-to-python-51203ac160e4?source=rss-f3023fd723c0------2</link>
            <guid isPermaLink="false">https://medium.com/p/51203ac160e4</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[code-newbie]]></category>
            <category><![CDATA[introduction]]></category>
            <category><![CDATA[code]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Besmire Thaqi]]></dc:creator>
            <pubDate>Thu, 14 Jun 2018 17:29:57 GMT</pubDate>
            <atom:updated>2021-03-22T17:07:09.708Z</atom:updated>
            <content:encoded><![CDATA[<h4>A brief introduction to Python programming for beginners.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bT6Uvry7kKvWAX7b6HF5Ag.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@unsplash?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a> on <a href="https://medium.com/photos/KwJ3FEuwRlE?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>Besides being a family of nonvenomous snakes, Python is also a high-level scripting/programming language. It was created by Guido van Rossum and released in 1991. It is widely used from developers for different purposes.</p><p><strong>Why do developers choose to work with Python?</strong></p><p>The best thing about Python is that you can get things done with less code comparing to other languages. It has a very simple syntax, and runs on an interpreter system, meaning that code can be executed as soon as it is written. It can be treated in an object-oriented way and functional way. Python can be used for web development (server-side), software development, data science, AI &amp; machine learning, solving complex mathematics and more.</p><p>Most of the biggest companies use Python for numerous reasons. It’s worth mentioning that Python is <em>Google’s</em> first choice and most of <em>Google’s</em> tools are developed with this language. <em>Facebook, Quora, Dropbox, Instagram, Spotify, Netflix, Reddi</em>t and more, have dedicated developers and engineers focused in Python and its frameworks.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/96/1*bUyeE55YjJUWl6yg-ixIcw.png" /></figure><h4>Starting with Python</h4><p>The goal is getting to know the syntax and the basics of this language. Let’s dig into a little bit of instructions and code!</p><p><strong>1.0 Installation</strong></p><p>If working in Linux or MacOS, then Python is already pre-installed there. But, if working in Windows, it needs be installed. Follow instructions <a href="https://www.python.org/downloads/">here</a>.</p><p><strong>1.1 Editors and </strong><a href="https://searchsoftwarequality.techtarget.com/definition/integrated-development-environment"><strong>IDE</strong></a></p><p>Any editor can be used by choice like Visual Studio Code, Brackets, Atom etc. Some of the specified ones and IDEs for Python are <a href="https://www.jetbrains.com/pycharm/">PyCharm</a> IDE from JetBrains, <a href="http://jupyter.org/install">Jupyter</a>, and <a href="https://pythonhosted.org/spyder/installation.html">Spyder</a>.</p><p><strong>1.2 Variables and types</strong></p><p>In Python, there is no need to declare variables or their type before using them. Regarding the numbers, it supports different types of numbers: integers (whole numbers), floats (decimals) and complex numbers.</p><pre># define an integer<br>myint = 1</pre><pre># define a float<br>myfloat = 1.2</pre><p>Strings are defined either with single quotes or double quotes.</p><pre># define a string with single quotes<br>mystring = &#39;Hello world!&#39;</pre><pre># define a string with double quotes<br>mystring = &quot;Hello world!&quot;</pre><pre># double quotes make it easy do use apostrophe in the string<br>mystring = &quot;Don&#39;t mind the apostrophe here!&quot;</pre><pre># string formatting, gets the value of defined variables<br>name = &quot;Jane&quot;<br>age = 20<br>print(&quot;My name is %s and I&#39;m %s years old.&quot; % (name, age))</pre><p>Simple operators can be also used in numbers and strings as well.</p><pre>two = 2<br>four = 4<br>print(two+four) # returns 6</pre><pre>two = &quot;two&quot;<br>four = &quot;four&quot;<br>print(two+&quot; &quot;+four) # returns two four</pre><pre>two = 2<br>four = &quot;four&quot;<br>print(two+four) # returns type error because it&#39;s unsupported</pre><p><strong>1.3 Lists</strong></p><p>Lists are basically like arrays. You can add as many elements as you want and you can iterate through the list.</p><pre># define a list<br>mylist = []</pre><pre># add elements to the list<br>mylist.append(1)<br>mylist.append(2)<br>mylist.append(3)</pre><pre># print the first element in the list<br>print(mylist[0]) # returns 1</pre><pre># iterate through the list<br>for element in mylist:<br>    print(element) # returns 1 2 3 each in new a line</pre><p><strong>1.4 Loops</strong></p><p>The example above shows how to iterate through a list. In Python it is also supported to iterate through elements with “range” function.</p><pre>for i in range(3):<br>    print(i) # returns 0, 1, 2</pre><pre>for i in range(3, 5):<br>    print(i) # returns 3, 4</pre><pre>for i in range(3, 10, 3):<br>    print(i) # returns 3, 6, 9</pre><p>“While” loops are also supported together with “break” and “continue”. The “break” is used to exit a loop and “continue” is used to skip the current block and return to the “for” or “while” in the beginning.</p><pre># while loop repeats as long as a condition is met<br>count = 1<br>while count &lt; 3:<br>   print(count) # returns 1, 2 <br>   count += 1 # raises the count variable for one</pre><pre># break condition in a loop is used to exit the loop<br>count = 1<br>while True:<br>    print(count) # returns 1, 2, 3<br>    count += 1<br>    if count &gt; 3:<br>        break # exits when the count is already 4</pre><pre># continue condition is used to skip the current block<br>for i in range(8):<br>    if i % 2 == 0: # checks if number is even in order to skip it<br>        continue<br>    print(i) # returns only odd numbers 1, 3, 5, 7</pre><p><strong>1.5 Conditions</strong></p><p>The boolean logic is used to evaluate conditions. Therefore; True or False is returned when evaluating or comparing conditions.</p><pre>i = 4<br>print(i&gt;5) # returns False<br>print(i==5) # returns False, two equal operators to check it&#39;s equal<br>print(i&lt;5) # returns True<br>print(i!=5) # returns True, != operator to check if it&#39;s not equal</pre><p>There are boolean operators (“<strong>and</strong>” or “<strong>or</strong>”) supported together with “<strong>in</strong>”, “<strong>is</strong>”, “<strong>not</strong>” operators.</p><pre>first = 1<br>second = 2<br>if first == 1 and second == 2:<br>    print(&quot;First and second number is 1 and 2.&quot;)</pre><pre>if first == 1 or one == 0:<br>    print(&quot;First number is either 1 or 0.&quot;)</pre><pre>if first in [0, 1, 2]:<br>    print(&quot;First number exists in the list.&quot;)</pre><p>Unlike the “<strong>==</strong>” operator, there is “<strong>is</strong>” operator that does not match the value of variables but the instances themselves. And the “<strong>not</strong>” condition checks the negotiation.</p><pre>i = [0, 1]<br>j = [0, 1]<br>print(i==j) # returns True<br>print(i is j) # returns False</pre><pre>print(not False) # returns True</pre><p><strong>1.6 Functions</strong></p><p>Functions are a convenient way to divide code into useful blocks, therefore; making it more readable and be able to reuse the code.</p><pre>def my_function():<br>    print(&quot;Here&#39;s a function!&quot;)</pre><pre>my_function() # returns Here&#39;s a function!</pre><pre>def my_function_with_args(name, age):<br>    print(&quot;%s is %s years old.&quot; % (name, age))</pre><pre>my_function_with_args(&quot;Jane&quot;, 20) # returns Jane is 20 years old.</pre><p><strong>1.7 Classes and objects</strong></p><p>An object is a unique instance of a data structure defined by a class. A class is like a template to create objects. Basically an object is an instance which is a copy of a class with actual values.</p><pre>class MyClass:<br>    name = &quot;Jane&quot;</pre><pre>    def my_function(self):<br>        print(&quot;A function inside a class&quot;)<br></pre><pre># creating an object/instance of the class<br>my_object = MyClass() # holds an object of the class MyClass</pre><pre># accessing the variables and functions defined in the class<br>print(my_object.name) # returns Jane<br>print(my_object.my_function()) # returns A function inside a class</pre><pre># multiple objects can be created from the same class<br>my_object_2 = MyClass()<br>print(my_object_2.name) # returns Jane<br>print(my_object_2.my_function()) # returns A function inside a class<br></pre><p><strong>1.8 Dictionaries</strong></p><p>A dictionary is a data type similar to arrays. The difference is that arrays use indexes, and dictionaries use <strong>keys</strong> and <strong>values</strong>. Each variable stored in a dictionary can be accessed using the key. A key can be any type like string, number, list, etc.</p><pre>fruits = {}<br>fruits[&quot;apple&quot;] = 10<br>fruits[&quot;banana&quot;] = 20<br>fruits[&quot;pear&quot;] = 50</pre><pre>print(fruits) # returns {&#39;apple&#39;: 10, &#39;banana&#39;: 20, &#39;pear&#39;: 50}</pre><pre># accessing the variable with the key &quot;apple&quot;<br>print(fruits[&quot;apple&quot;]) # returns 10</pre><pre># iterating through the dictionary<br>for fruit, amount in fruits.items():<br>    print(&quot;Fruit and amount:&quot;, fruit, amount)</pre><pre># returns as shown below:<br># Fruit and amount: apple 10<br># Fruit and amount: banana 20<br># Fruit and amount: blueberries 50</pre><p>So far we have covered the syntax and the basics of Python like variables, operators, lists, conditions, functions, classes and objects, and dictionaries. To learn more and dig deeper, practice is required of course, and many other sources for tutorials and books can be helpful too.</p><h4>Books and sources to learn</h4><p>First, there are great forums and communities to join and visit such as <a href="https://python-forum.io/">PyForum</a>. Then, also any course or tutorial that doesn’t cost much and covers intro in Udemy or Coursera is highly recommended.</p><p>Different sources that offer introductions (for free) and tutorials such as:</p><ul><li><a href="http://www.python.org/about/gettingstarted/"><em>python.org</em></a></li><li><a href="http://www.learnpython.org/"><em>learnpython.org</em></a></li><li><a href="http://www.realpython.com/"><em>realpython.com</em></a><em> and more.</em></li></ul><p>Some of the books for Python beginners that have good reviews:</p><ul><li><em>Python Crash Course by Eric Matthes (No Starch Press, 2016)</em></li><li><em>Head-first Python, 2nd edition by Paul Barry (O’Reilly, 2016)</em></li><li><em>Think Python, How to think like a Computer Scientist, 2nd edition by Allen B. Downey (O’Reilly, 2015)</em></li><li><em>Learn Python 3 The Hard Way by Zedd A. Shaw (Addison-Wesley, 2016)</em></li></ul><h4>A short recap</h4><p>A brief introduction to Python programming language for beginners explains where this language comes from, why is it widely popular and who uses it for development. Understanding the syntax and the basics have been covered and explained with examples using pieces of code.</p><p>Moreover, the beginner’s guide and a developer’s will to learn does not stop here. There are really good sources like books and tutorials (cheap and free) that can be helpful to read and follow.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=51203ac160e4" width="1" height="1" alt=""><hr><p><a href="https://medium.com/python-pandemonium/introduction-to-python-51203ac160e4">Introduction to Python</a> was originally published in <a href="https://medium.com/python-pandemonium">Python Pandemonium</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>