<?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 Pratik Asija on Medium]]></title>
        <description><![CDATA[Stories by Pratik Asija on Medium]]></description>
        <link>https://medium.com/@asijapratik?source=rss-a46220a9b893------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*vdYYOayJcPBpNFJw_vpApQ.jpeg</url>
            <title>Stories by Pratik Asija on Medium</title>
            <link>https://medium.com/@asijapratik?source=rss-a46220a9b893------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 16:07:00 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@asijapratik/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[Unleashing the Power of AI: A Glimpse into an Exciting Future]]></title>
            <link>https://medium.com/@asijapratik/unleashing-the-power-of-ai-a-glimpse-into-an-exciting-future-28dd78aea47f?source=rss-a46220a9b893------2</link>
            <guid isPermaLink="false">https://medium.com/p/28dd78aea47f</guid>
            <category><![CDATA[future]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[future-technology]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[power-of-ai]]></category>
            <dc:creator><![CDATA[Pratik Asija]]></dc:creator>
            <pubDate>Sat, 15 Jul 2023 12:27:54 GMT</pubDate>
            <atom:updated>2023-07-15T12:27:54.316Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*EZnD5PE8jkVhMgam" /><figcaption>Photo by <a href="https://unsplash.com/@sortino?utm_source=medium&amp;utm_medium=referral">Joshua Sortino</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Prepare to be amazed as we explore the breathtaking possibilities that lie ahead in the realm of Artificial Intelligence (AI). The best is yet to come, and with each passing day, AI is poised to deliver a future filled with boundless opportunities and extraordinary advancements. From revolutionizing industries to transforming the way we live, AI is on the verge of a breakthrough that will leave us in awe<strong>.</strong></p><ol><li><strong>Augmenting Human Potential:</strong> Imagine a world where AI acts as your trusted companion, enabling you to achieve superhuman feats. With AI by your side, you’ll transcend your limitations, accomplishing tasks faster, smarter, and more efficiently. From intelligent personal assistants anticipating your needs to AI-powered insights guiding your decision-making, this is just the beginning of an era where humans and AI collaborate to unlock their full potential.</li><li><strong>Tailored Experiences at Your Fingertips:</strong> Get ready for a personalized revolution! AI will reshape the way we experience the world by tailoring every interaction to suit our unique preferences. From personalized recommendations that truly understand your desires to hyper-personalized healthcare that caters to your specific needs, AI will make each moment truly unforgettable. Get ready for a world where technology adapts to you, offering an unparalleled level of customization.</li><li><strong>Igniting Innovation in Uncharted Territories:</strong> AI is set to blaze trails into uncharted territories, transcending current boundaries and transforming industries we never thought possible. Imagine AI-driven breakthroughs in healthcare that accelerate the development of life-saving treatments or AI-powered sustainability solutions that propel us towards a greener future. The possibilities are limitless, and AI will be at the forefront, pioneering innovation like never before.</li><li><strong>Empowering a Connected World:</strong> AI will be the glue that connects our world, bringing people closer than ever before. From seamless language translation to AI-driven social platforms fostering meaningful connections, AI will break down barriers and create a global community. By eradicating communication gaps and fostering understanding, AI will build bridges and foster a sense of unity in an increasingly interconnected world.</li><li><strong>Envisioning a Bright and Prosperous Future:</strong> Buckle up for a future that is brighter than ever! AI’s potential to drive economic growth, create new job opportunities, and enhance productivity is unparalleled. Industries will flourish as AI optimizes processes, fuels innovation, and unleashes human creativity. Embrace the infinite possibilities of a future where AI elevates our lives, paving the way for prosperity and unparalleled success.</li></ol><p><strong>Conclusion:</strong> Get ready to witness the extraordinary! The best of AI is on the horizon, waiting to astonish us with its limitless potential. As AI continues to evolve, it will reshape industries, amplify human capabilities, and connect us in ways we’ve only dreamed of. Embrace the forthcoming AI revolution, and be prepared to experience a future that will surpass your wildest expectations. The age of AI is here, and the possibilities are endless. Step into a world where innovation knows no bounds, and let the power of AI unlock a future brimming with unimaginable wonders.</p><ul><li><a href="https://towardsdatascience.com/our-ai-future-473245c11438">Our AI Future</a></li><li><a href="https://medium.com/a-passion-to-evolve/ai-future-complicated-by-self-interest-economics-politics-1455aa1f7f9c">AI Future Complicated by Self-Interest, Economics &amp; Politics</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=28dd78aea47f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Python Game — Guess The Number]]></title>
            <link>https://medium.com/@asijapratik/python-game-guess-the-number-228a07ba6c90?source=rss-a46220a9b893------2</link>
            <guid isPermaLink="false">https://medium.com/p/228a07ba6c90</guid>
            <category><![CDATA[gaming]]></category>
            <category><![CDATA[ui-design]]></category>
            <category><![CDATA[tkinter]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[game-development]]></category>
            <dc:creator><![CDATA[Pratik Asija]]></dc:creator>
            <pubDate>Tue, 21 Feb 2023 05:10:37 GMT</pubDate>
            <atom:updated>2023-02-21T05:12:29.191Z</atom:updated>
            <content:encoded><![CDATA[<h3>Python Game — Guess The Number</h3><p>Have you ever played the classic <strong>“Guess the Number”</strong> game? It’s a simple game where the computer generates a random number and the player has to guess what the number is. The game keeps track of the number of guesses it takes the player to guess the correct number, and displays it at the end of the game. In this article, we’ll show you how to create a UI-based version of the “Guess the Number” game using Python and the tkinter library.</p><p>tkinter is a built-in Python library for creating graphical user interfaces (GUIs). With tkinter, you can easily create windows, buttons, labels, and other graphical elements that allow users to interact with your Python programs.</p><p>We’ll start by creating a simple Python class for our game, which will initialize the game’s variables and create the UI elements for the game. Then, we’ll define a method for checking the player’s guess and updating the UI accordingly. Finally, we’ll start the game by creating an instance of our class and running the UI loop.</p><p>By the end of this article, you’ll have a fully functional UI-based “Guess the Number” game that you can play and share with others. Let’s get started!</p><p>So let’s jump straight to the code now!</p><pre>import tkinter as tk<br>import random<br><br>class GuessTheNumberGUI:<br>    def __init__(self):<br>        self.root = tk.Tk()<br>        self.root.title(&quot;Guess the Number&quot;)<br><br>        self.number = random.randint(1, 100)<br>        self.guesses = 0<br><br>        self.label = tk.Label(self.root, text=&quot;I&#39;m thinking of a number between 1 and 100.&quot;)<br>        self.label.pack(padx=10, pady=10)<br><br>        self.entry = tk.Entry(self.root)<br>        self.entry.pack(padx=10, pady=10)<br><br>        self.button = tk.Button(self.root, text=&quot;Guess&quot;, command=self.check_guess)<br>        self.button.pack(padx=10, pady=10)<br><br>        self.result = tk.Label(self.root, text=&quot;&quot;)<br>        self.result.pack(padx=10, pady=10)<br><br>    def check_guess(self):<br>        guess = int(self.entry.get())<br>        self.guesses += 1<br>        if guess &lt; self.number:<br>            self.result.config(text=&quot;Too low, try again!&quot;)<br>        elif guess &gt; self.number:<br>            self.result.config(text=&quot;Too high, try again!&quot;)<br>        else:<br>            self.result.config(text=&quot;Congratulations, you guessed the number in {} attempts!&quot;.format(self.guesses))<br>            self.entry.config(state=&quot;disabled&quot;)<br>            self.button.config(state=&quot;disabled&quot;)<br><br>    def start(self):<br>        self.root.mainloop()<br><br>game = GuessTheNumberGUI()<br>game.start()</pre><p>This version of the game uses a simple UI with a label, entry field, button, and result label. The player enters their guess into the entry field and clicks the button to check their guess. The result label displays whether the guess was too high, too low, or correct, and also displays the number of guesses it took the player to guess the correct number. Once the player guesses the correct number, the entry field and button are disabled so the player can’t make any more guesses.</p><p>The output looks like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/395/1*GQpyXhNEPpBuUU7gzFGJMw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/486/1*T8UtLIRosEjv8m4tRkNr-g.png" /></figure><p>Play and enjoy with your friends, compete on who uses the minimum number of guesses.</p><p>Do checkout more of my games in python</p><ul><li><a href="https://medium.com/@asijapratik/python-game-guess-the-number-228a07ba6c90">Python Game — Guess The Number</a></li><li><a href="https://medium.com/@asijapratik/python-game-pong-ball-6525f9f8f84a">Python Game — Pong Ball</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=228a07ba6c90" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Python Game — Pong Ball]]></title>
            <link>https://towardsdev.com/python-game-pong-ball-6525f9f8f84a?source=rss-a46220a9b893------2</link>
            <guid isPermaLink="false">https://medium.com/p/6525f9f8f84a</guid>
            <category><![CDATA[games]]></category>
            <category><![CDATA[game-development]]></category>
            <category><![CDATA[gaming]]></category>
            <category><![CDATA[gaming-articles]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Pratik Asija]]></dc:creator>
            <pubDate>Mon, 20 Feb 2023 10:24:20 GMT</pubDate>
            <atom:updated>2023-02-27T16:09:55.960Z</atom:updated>
            <content:encoded><![CDATA[<h3>Python Game — Pong Ball</h3><p>In this article, I am going to design a game known as ‘Pong Game’ using Python. It’s a very simple game to create. The game is a simple pong ball game we used to play in childhood. The main objective is to bounce the ball on the paddle at the bottom of the screen and never let it the bottom part of the screen. The score is counted as many times the ball hits the paddle. Overall, the game provides a fun and challenging experience for players of all ages.</p><p>I have already introduced you to Pygame and Tkinter in the below article.</p><p><a href="https://medium.com/@asijapratik/python-game-avoid-obstacles-62469a768e34">Python Game — Avoid Obstacles</a></p><p>To maintain the simplicity in this game, I have not added modes of play in this game which can be done easily by creating user interface using Tkinter and backend part can be managed by adding if statements and changing the paddle size or speed or speed of the ball to make it harder to play as i have done in the above ‘Avoid Obstacles’ game if you wanna check it out.</p><p>So let’s jump to the code now:</p><pre>import pygame<br>import random<br><br># Initialize Pygame<br>pygame.init()<br><br># Set the screen size<br>screen_width = 800<br>screen_height = 600<br>screen = pygame.display.set_mode((screen_width, screen_height))<br><br># Set the game clock<br>clock = pygame.time.Clock()<br><br># Set the colors<br>BLACK = (0, 0, 0)<br>WHITE = (255, 255, 255)<br><br># Set the font<br>font = pygame.font.SysFont(&#39;Arial&#39;, 30)<br><br># Set the ball properties<br>ball_pos = [screen_width // 2, screen_height // 2]<br>ball_radius = 10<br>ball_speed = [3, 3]<br><br># Set the paddle properties<br>paddle_width = 100<br>paddle_height = 10<br>paddle_speed = 5<br><br>paddle_pos = [(screen_width - paddle_width) // 2, screen_height - paddle_height]<br><br># Set the score<br>score = 0<br><br># Main game loop<br>running = True<br>while running:<br><br>    # Handle events<br>    for event in pygame.event.get():<br>        if event.type == pygame.QUIT:<br>            running = False<br><br>    # Move the paddle<br>    keys = pygame.key.get_pressed()<br>    if keys[pygame.K_LEFT] and paddle_pos[0] &gt; 0:<br>        paddle_pos[0] -= paddle_speed<br>    if keys[pygame.K_RIGHT] and paddle_pos[0] &lt; screen_width - paddle_width:<br>        paddle_pos[0] += paddle_speed<br><br>    # Move the ball<br>    ball_pos[0] += ball_speed[0]<br>    ball_pos[1] += ball_speed[1]<br><br>    # Check for ball collision with the walls<br>    if ball_pos[0] &lt;= ball_radius or ball_pos[0] &gt;= screen_width - ball_radius:<br>        ball_speed[0] = -ball_speed[0]<br>    if ball_pos[1] &lt;= ball_radius:<br>        ball_speed[1] = -ball_speed[1]<br><br>    # Check for ball collision with the paddle<br>    if ball_pos[1] &gt;= paddle_pos[1] - ball_radius and paddle_pos[0] &lt;= ball_pos[0] &lt;= paddle_pos[0] + paddle_width:<br>        ball_speed[1] = -ball_speed[1]<br>        score += 1<br><br>    # Check for game over<br>    if ball_pos[1] &gt;= screen_height:<br>        running = False<br><br>    # Draw the game objects<br>    screen.fill(BLACK)<br>    pygame.draw.circle(screen, WHITE, ball_pos, ball_radius)<br>    pygame.draw.rect(screen, WHITE, (paddle_pos[0], paddle_pos[1], paddle_width, paddle_height))<br>    score_text = font.render(&#39;Score: &#39; + str(score), True, WHITE)<br>    screen.blit(score_text, (20, 20))<br><br>    # Update the screen<br>    pygame.display.flip()<br><br>    # Set the game speed<br>    clock.tick(60)<br>    <br>print(&quot;Score =&quot;,score)<br><br># Quit Pygame<br>pygame.quit()</pre><p>If you want to run this game on your system, you’ll need to install from python.org. And then install pip using</p><pre>py -m ensurepip</pre><p>Once pip is installed, you’ll need to set it to the path system variable as well, to be able to use it. Then check if pip is installed using</p><pre>pip -V</pre><p>Then install pygame using</p><pre>pip install pygame</pre><p>Then use this code above and save it as .py file to run it in python.</p><p>The output will look something like:-</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dQXr-8yq_10rL-mVU-DBkA.png" /><figcaption>Pong Game</figcaption></figure><p>Try out this game with your friends, and beat each other’s score. Hope you enjoy this article. I have more articles like this, which you can check out.</p><ul><li><a href="https://towardsdev.com/creating-a-simple-game-using-python-and-pygame-7f3672457f9d">Creating a simple game using Python and Pygame</a></li><li><a href="https://medium.com/@asijapratik/python-game-avoid-obstacles-62469a768e34">Python Game — Avoid Obstacles</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6525f9f8f84a" width="1" height="1" alt=""><hr><p><a href="https://towardsdev.com/python-game-pong-ball-6525f9f8f84a">Python Game — Pong Ball</a> was originally published in <a href="https://towardsdev.com/">Towards Dev</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Python Game — Avoid Obstacles]]></title>
            <link>https://towardsdev.com/python-game-avoid-obstacles-62469a768e34?source=rss-a46220a9b893------2</link>
            <guid isPermaLink="false">https://medium.com/p/62469a768e34</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[ui]]></category>
            <category><![CDATA[games]]></category>
            <category><![CDATA[design]]></category>
            <category><![CDATA[game-development]]></category>
            <dc:creator><![CDATA[Pratik Asija]]></dc:creator>
            <pubDate>Fri, 17 Feb 2023 11:02:33 GMT</pubDate>
            <atom:updated>2023-02-28T18:38:40.647Z</atom:updated>
            <content:encoded><![CDATA[<h3>Python Game — Avoid Obstacles</h3><p>In this article, I am going to design a game known as ‘Avoid Obstacles’ using Python. It’s a very simple game to create. The game is a simple obstacle avoidance game made with <strong>Pygame</strong> in Python. The player controls a rectangular object at the bottom of the screen and must avoid colliding with randomly generated obstacles that fall from the top of the screen. The game features a score counter that increases as the player successfully avoids obstacles. The game includes a user interface built with <strong>tkinter</strong> that allows the player to select from three different difficulty modes (e<em>asy, medium, and hard</em>), which affect the speed of the falling obstacles. Overall, the game provides a fun and challenging experience for players of all ages.</p><p>Pygame is a set of Python modules designed for writing video games. It provides a wide variety of functions and classes that are useful for creating games with graphics, sound, and user input. Pygame is built on top of the Simple DirectMedia Layer (SDL), a popular cross-platform multimedia library.</p><p>Tkinter is a standard Python library for creating graphical user interfaces (GUIs). It provides a set of widgets (such as buttons, labels, and text boxes) and a layout manager that allows you to arrange those widgets in a window. Tkinter is cross-platform, which means that GUIs created with it will work on Windows, macOS, and Linux. It is also simple and easy to use, making it a great choice for creating simple GUIs quickly.</p><p>Let’s jump straight to code then. The code is easy to understand and I have also added comments to it to make it more readable and understandable</p><pre>import random<br>import pygame<br>import tkinter as tk<br><br># initialize pygame<br>pygame.init()<br><br># set up the game window<br>window_width = 640<br>window_height = 480<br>window = pygame.display.set_mode((window_width, window_height))<br>pygame.display.set_caption(&quot;Avoid Obstacles&quot;)<br><br># set up the game objects<br>player_width = 50<br>player_height = 50<br>player_x = window_width // 2 - player_width // 2<br>player_y = window_height - player_height - 10<br><br>obstacle_width = 50<br>obstacle_height = 50<br>obstacle_speed = 5<br>obstacles = []<br><br># set up the game font<br>font = pygame.font.Font(None, 30)<br><br># set up the tkinter window for selecting the game mode<br>def set_easy_mode():<br>    global obstacle_speed<br>    obstacle_speed = 3<br>    root.destroy()<br><br>def set_medium_mode():<br>    global obstacle_speed<br>    obstacle_speed = 5<br>    root.destroy()<br><br>def set_hard_mode():<br>    global obstacle_speed<br>    obstacle_speed = 7<br>    root.destroy()<br><br>root = tk.Tk()<br>root.title(&quot;Select Game Mode&quot;)<br>easy_button = tk.Button(root, text=&quot;Easy&quot;, command=set_easy_mode)<br>easy_button.pack()<br>medium_button = tk.Button(root, text=&quot;Medium&quot;, command=set_medium_mode)<br>medium_button.pack()<br>hard_button = tk.Button(root, text=&quot;Hard&quot;, command=set_hard_mode)<br>hard_button.pack()<br>root.mainloop()<br><br># game loop<br>score = 0<br>clock = pygame.time.Clock()<br>running = True<br>while running:<br>    # handle events<br>    for event in pygame.event.get():<br>        if event.type == pygame.QUIT:<br>            running = False<br>    <br>    # move the player<br>    keys = pygame.key.get_pressed()<br>    if keys[pygame.K_LEFT] and player_x &gt; 0:<br>        player_x -= 5<br>    elif keys[pygame.K_RIGHT] and player_x &lt; window_width - player_width:<br>        player_x += 5<br><br>    # move the obstacles and add new ones<br>    for obstacle in obstacles:<br>        obstacle[1] += obstacle_speed<br>    if len(obstacles) == 0 or obstacles[-1][1] &gt; 50:<br>        x = random.randint(0, window_width - obstacle_width)<br>        obstacles.append([x, -obstacle_height])<br>    if obstacles[0][1] &gt; window_height:<br>        obstacles.pop(0)<br><br>    # check for collisions<br>    for obstacle in obstacles:<br>        if player_x &lt; obstacle[0] + obstacle_width and player_x + player_width &gt; obstacle[0] and player_y &lt; obstacle[1] + obstacle_height and player_y + player_height &gt; obstacle[1]:<br>            running = False<br>    <br>    # update the score<br>    score += 1<br><br>    # draw the game<br>    window.fill((0, 0, 0))<br>    for obstacle in obstacles:<br>        pygame.draw.rect(window, (255, 0, 0), (obstacle[0], obstacle[1], obstacle_width, obstacle_height))<br>    pygame.draw.rect(window, (0, 0, 255), (player_x, player_y, player_width, player_height))<br>    score_text = font.render(&quot;Score: &quot; + str(score), True, (255, 255, 255))<br>    window.blit(score_text, (window_width // 2 - score_text.get_width() // 2, 20))<br><br>    # update the display<br>    pygame.display.update()<br><br>    # limit the frame rate<br>    clock.tick(60)<br><br># clean up pygame<br>pygame.quit()<br>print(&quot;Score =&quot;,score)</pre><p>If you want to run this game on your system, you’ll need to install from python.org. And then install pip using</p><pre>py -m ensurepip</pre><p>Once pip is installed, you’ll need to set it to the path system variable as well, to be able to use it. Then check if pip is installed using</p><pre>pip -V</pre><p>Then install pygame and Tkinter using</p><pre>pip install pygame<br>pip install Tkinter</pre><p>Then use this code above and save it as .py file to run it in python.</p><p>Final Output will look something like</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/184/1*Y9Kq-WlEHYhZsJ_TlD3nVw.png" /><figcaption>This gives you option to select the mode you want to play. Harder the mode, greater the speed of obstacles will be.</figcaption></figure><figure><img alt="The longer you avoid the obstacles, the more you score." src="https://cdn-images-1.medium.com/max/644/1*UJx1DUqPOxb64lhDA2AbiQ.png" /><figcaption>The longer you avoid the obstacles, the more you score.</figcaption></figure><p>Try out this game with your friends, and beat each other’s score. Hope you enjoy this article. I have more articles like this, which you can check out.</p><ul><li><a href="https://towardsdev.com/creating-a-simple-game-using-python-and-pygame-7f3672457f9d">Creating a simple game using Python and Pygame</a></li><li><a href="https://medium.com/geekculture/write-a-simple-python-program-19c8790a260f">Write A Simple Python Game</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=62469a768e34" width="1" height="1" alt=""><hr><p><a href="https://towardsdev.com/python-game-avoid-obstacles-62469a768e34">Python Game — Avoid Obstacles</a> was originally published in <a href="https://towardsdev.com/">Towards Dev</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Getting Started with Artificial Intelligence]]></title>
            <link>https://towardsdev.com/getting-started-with-artificial-intelligence-2315e09b16c0?source=rss-a46220a9b893------2</link>
            <guid isPermaLink="false">https://medium.com/p/2315e09b16c0</guid>
            <category><![CDATA[python-programming]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[science-fiction]]></category>
            <dc:creator><![CDATA[Pratik Asija]]></dc:creator>
            <pubDate>Wed, 15 Feb 2023 11:58:26 GMT</pubDate>
            <atom:updated>2023-02-20T13:24:26.033Z</atom:updated>
            <content:encoded><![CDATA[<p>Artificial intelligence (AI) is a rapidly growing field that has the potential to revolutionize the way we live and work. With the help of Python, an open-source programming language, you can start your journey into the world of AI. In this article, I will guide you through the steps required to get started with artificial intelligence using Python.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*udtN7qYTxM0Cfm4w" /><figcaption>Photo by <a href="https://unsplash.com/@maximalfocus?utm_source=medium&amp;utm_medium=referral">Maximalfocus</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p><strong>Step 1: Install Python</strong></p><p>The first step to getting started with AI using Python is to install Python on your computer. Python is available for Windows, macOS, and Linux operating systems. You can download the latest version of Python from the official website of Python (<a href="https://www.python.org/downloads/">https://www.python.org/downloads/</a>). Once you have downloaded the installer, simply follow the installation instructions.</p><p><strong>Step 2: Install Required Libraries</strong></p><p>To work with AI in Python, you will need to install several libraries, including <strong>NumPy, Pandas, Matplotlib, and Scikit-learn</strong>. These libraries will help you perform data analysis, visualization, and machine learning. You can install these libraries using the pip package manager, which is included with Python.</p><p>To install these libraries, open the command prompt (Windows) or terminal (macOS/Linux) and type the following commands:</p><pre>pip install numpy<br>pip install pandas <br>pip install matplotlib <br>pip install scikit-learn</pre><p><strong>Step 3: Choose a Dataset</strong></p><p>Once you have installed the required libraries, it’s time to choose a dataset to work with. There are many publicly available datasets that you can use, such as the Iris dataset, which contains data on three different species of iris flowers, or the Boston Housing dataset, which contains data on housing prices in Boston. You can download these datasets from websites such as Kaggle (<a href="https://www.kaggle.com/datasets">https://www.kaggle.com/datasets</a>) or the UCI Machine Learning Repository (<a href="https://archive.ics.uci.edu/ml/index.php">https://archive.ics.uci.edu/ml/index.php</a>).</p><p><strong>Step 4: Load and Analyze the Dataset</strong></p><p>After you have chosen a dataset, the next step is to load the data into Python and analyze it. You can use the Pandas library to load data from CSV files, Excel files, or databases. Once you have loaded the data, you can use the <strong>NumPy</strong> and<strong> Matplotlib</strong> libraries to perform data analysis and visualization.</p><p>Here is an example code to load the Iris dataset and display the first five rows of data:</p><pre>pythonCopy code</pre><pre>import pandas as pd</pre><pre># Load data<br>data = pd.read_csv(&#39;iris.csv&#39;)</pre><pre># Display the first five rows of data<br>print(data.head())</pre><p><strong>Step 5: Prepare the Data</strong></p><p>Before you can start building an AI model, you need to prepare the data. This involves cleaning the data, handling missing values, and converting categorical variables into numerical variables. You can use the Pandas library to perform these tasks.</p><p>Here is an example code to convert categorical variables into numerical variables:</p><pre>pythonCopy code</pre><pre>import pandas as pd</pre><pre># Load data<br>data = pd.read_csv(&#39;iris.csv&#39;)</pre><pre># Convert categorical variables into numerical variables<br>data[&#39;species&#39;] = data[&#39;species&#39;].map({&#39;setosa&#39;: 0, &#39;versicolor&#39;: 1, &#39;virginica&#39;: 2})</pre><p><strong>Step 6: Build the AI Model</strong></p><p>Now that the data is prepared, you can start building the AI model. There are many machine learning algorithms that you can use, such as<strong> linear regression, logistic regression, decision trees, and neural networks</strong>. In this example, I will use the Scikit-learn library to build a simple decision tree model.</p><p>Here is an example code to build a decision tree model:</p><pre>pythonCopy code</pre><pre>import pandas as pd<br>from sklearn.tree import DecisionTreeClassifier<br>from sklearn.model_selection import train_test_split</pre><pre># Load data<br>data = pd.read_csv(&#39;iris.csv&#39;)</pre><pre># Prepare data<br>data[&#39;species&#39;] = data[&#39;species&#39;].map({&#39;setosa&#39;: 0, &#39;versicolor&#39;: 1, &#39;virginica&#39;: 2})<br>X = data.drop([&#39;species&#39;], axis=1)<br>y = data[&#39;species&#39;]</pre><pre># Split data into training and testing sets<br>X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)</pre><pre># Build decision tree model<br>model = DecisionTreeClassifier()<br>model.fit(X_train, y_train)</pre><pre># Evaluate model<br>score = model.score(X_test, y_test)<br>print(&#39;Model accuracy:&#39;, score)</pre><p>In this code, we first load the Iris dataset and prepare the data by converting the categorical variable ‘species’ into numerical variables. We then split the data into training and testing sets using the<em> train_test_split </em>function from Scikit-learn. Next, we build a decision tree model using the DecisionTreeClassifier class and fit the model to the training data using the fit method. Finally, we evaluate the model on the testing data using the score method and print the model accuracy.</p><p><strong>Step 7: Improve the AI Model</strong></p><p>Once you have built an AI model, you can try to improve its performance by tweaking the parameters or using a different algorithm. You can also try to improve the data preprocessing step by using different techniques, such as feature scaling, feature selection, or dimensionality reduction.</p><p>Here is an example code to improve the decision tree model by setting the maximum depth to 3:</p><pre>pythonCopy code</pre><pre>import pandas as pd<br>from sklearn.tree import DecisionTreeClassifier<br>from sklearn.model_selection import train_test_split</pre><pre># Load data<br>data = pd.read_csv(&#39;iris.csv&#39;)</pre><pre># Prepare data<br>data[&#39;species&#39;] = data[&#39;species&#39;].map({&#39;setosa&#39;: 0, &#39;versicolor&#39;: 1, &#39;virginica&#39;: 2})<br>X = data.drop([&#39;species&#39;], axis=1)<br>y = data[&#39;species&#39;]</pre><pre># Split data into training and testing sets<br>X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)</pre><pre># Build decision tree model with max depth of 3<br>model = DecisionTreeClassifier(max_depth=3)<br>model.fit(X_train, y_train)</pre><pre># Evaluate model<br>score = model.score(X_test, y_test)<br>print(&#39;Model accuracy:&#39;, score)</pre><p>In this code, we set the maximum depth of the decision tree to 3 using the max_depth parameter of the <strong>DecisionTreeClassifier </strong>class. This can help to prevent overfitting and improve the model accuracy.</p><p><strong>Step 8: Deploy the AI Model</strong></p><p>Once you have built an AI model that meets your requirements, you can deploy it in a production environment. This can involve integrating the model into a web application, a mobile app, or an IoT device. You can use frameworks such as <strong>Flask</strong> or <strong>Django</strong> to build a web API for your model, or use tools such as <strong>TensorFlow Lite</strong> to optimize the model for deployment on mobile or embedded devices.</p><p>In this article, I have shown you how to get started with artificial intelligence using Python. I have covered the basic steps of the machine learning process, including data preparation, model building, and model evaluation. I have also shown you how to use popular Python libraries such as <strong>Pandas, Scikit-learn, and Matplotlib</strong> to perform these tasks.</p><p>By following these steps, you can start building your own AI models and solving real-world problems using machine learning. Remember that machine learning is an iterative process, and it may take some trial and error to achieve the best results. Don’t be afraid to experiment with different algorithms, parameters, and techniques to find the optimal solution.</p><p>Lastly, I recommend that you continue learning and exploring the world of artificial intelligence. There are many online resources, courses, and communities that can help you expand your knowledge and skills. Here are some useful resources to get you started:</p><ul><li><strong>Coursera:</strong> Machine Learning by Andrew Ng</li><li><strong>Kaggle:</strong> a platform for machine learning competitions and tutorials</li><li><strong>TensorFlow:</strong> an open-source machine learning platform developed by Google</li><li><strong>PyTorch:</strong> an open-source machine learning library developed by Facebook AI Research</li><li><strong>Scikit-learn:</strong> a popular Python library for machine learning</li></ul><p>I hope that this article has provided you with a good introduction to getting started with artificial intelligence using Python. Good luck with your AI journey!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2315e09b16c0" width="1" height="1" alt=""><hr><p><a href="https://towardsdev.com/getting-started-with-artificial-intelligence-2315e09b16c0">Getting Started with Artificial Intelligence</a> was originally published in <a href="https://towardsdev.com/">Towards Dev</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Object Oriented Programming in Python]]></title>
            <link>https://towardsdev.com/object-oriented-programming-in-python-64af4d68dd06?source=rss-a46220a9b893------2</link>
            <guid isPermaLink="false">https://medium.com/p/64af4d68dd06</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[oop]]></category>
            <category><![CDATA[object-oriented]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Pratik Asija]]></dc:creator>
            <pubDate>Thu, 09 Feb 2023 11:27:49 GMT</pubDate>
            <atom:updated>2023-02-10T19:38:36.477Z</atom:updated>
            <content:encoded><![CDATA[<blockquote><strong>Object-Oriented Programming (OOP)</strong> is a programming paradigm that is based on the concept of objects, which can contain data and functions that operate on that data. OOP is a fundamental concept in Python, and is used extensively in the development of applications, both small and large.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*MUTNOUcTt4236SKv" /><figcaption>Photo by <a href="https://unsplash.com/@markusspiske?utm_source=medium&amp;utm_medium=referral">Markus Spiske</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>In this article, we will go through a step-by-step guide to understanding and working with OOP in Python.</p><p><strong>Step 1: Understanding Classes and Objects</strong></p><p>The most basic building block of OOP in Python is the class. A <strong>class</strong> is a blueprint for creating objects, which are instances of the class. Each object created from a class has its own set of data and functions, but they are all based on the same class definition.</p><p>For example, let’s consider a class “Person”. A person has a name and an age. We can define this class as follows:</p><pre>rubyCopy code</pre><pre>class Person:<br>    def __init__(self, name, age):<br>        self.name = name<br>        self.age = age</pre><p>The __init__ function is a special function in Python classes that is called when an object is created from the class. The self parameter refers to the object being created, and it is used to store the data associated with the object.</p><p><strong>Step 2: Defining Instance Methods</strong></p><p>In addition to data, objects can also have functions, known as methods. These methods can be used to operate on the data stored in the object. For example, let’s add a method greet to the Person class that prints a greeting message:</p><pre>rubyCopy code</pre><pre>class Person:<br>    def __init__(self, name, age):<br>        self.name = name<br>        self.age = age</pre><pre>    def greet(self):<br>        print(&quot;Hello, my name is&quot;, self.name)</pre><p><strong>Step 3: Creating Objects</strong></p><p>Once we have defined a class, we can create objects from it. To create an object, we simply call the class as if it were a function:</p><pre>makefileCopy code</pre><pre>person = Person(&quot;John Doe&quot;, 30)</pre><p>This creates a new Person object, and stores it in the person variable. We can access the data and functions of the object using the dot notation:</p><pre>pythonCopy code</pre><pre>print(person.name) # Output: John Doe<br>print(person.age) # Output: 30<br>person.greet() # Output: Hello, my name is John Doe</pre><p><strong>Step 4: Inheritance</strong></p><p>One of the key benefits of OOP is the ability to create new classes that are based on existing classes. This is known as inheritance, and it allows you to create new classes that have all the properties and methods of the base class, but with additional or modified functionality.</p><p>For example, let’s create a new class Student that inherits from the Person class:</p><pre>rubyCopy code</pre><pre>class Student(Person):<br>    def __init__(self, name, age, student_id):<br>        super().__init__(name, age)<br>        self.student_id = student_id</pre><p>The super() function is used to call the __init__ method of the base class, ensuring that the data is correctly initialized. The Student class now has all the properties and methods of the Person class, plus the additional student_id property.</p><p><strong>Step 5: Polymorphism</strong></p><p>Polymorphism is the ability of a class to take on multiple forms. In OOP, this means that a single method can have different implementations in different classes, depending on the data being operated on. For example, let’s consider a method info that prints information about a person or student:</p><pre>pythonCopy code</pre><pre>class Person:<br>    def __init__(self, name, age):<br>        self.name = name<br>        self.age = age</pre><pre>    def info(self):<br>        print(&quot;Name:&quot;, self.name)<br>        print(&quot;Age:&quot;, self.age)</pre><pre>class Student(Person):<br>    def __init__(self, name, age, student_id):<br>        super().__init__(name, age)<br>        self.student_id = student_id</pre><pre>    def info(self):<br>        super().info()<br>        print(&quot;Student ID:&quot;, self.student_id)</pre><p>In this example, both the Person and Student classes have an info method, but the implementation is different depending on the type of object. When we call the info method on a Person object, it prints the name and age, while when we call the info method on a Student object, it also prints the student ID. This is an example of polymorphism in action.</p><p>In conclusion, <strong>OOP</strong> is a powerful programming paradigm that allows you to model real-world objects and relationships in your code. By using <strong>classes, inheritance, and polymorphism</strong>, you can create robust and reusable code that is easy to maintain and extend.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=64af4d68dd06" width="1" height="1" alt=""><hr><p><a href="https://towardsdev.com/object-oriented-programming-in-python-64af4d68dd06">Object Oriented Programming in Python</a> was originally published in <a href="https://towardsdev.com/">Towards Dev</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[File Handling in Python]]></title>
            <link>https://towardsdev.com/file-handling-in-python-e9bc2c254ed1?source=rss-a46220a9b893------2</link>
            <guid isPermaLink="false">https://medium.com/p/e9bc2c254ed1</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[file-handling-in-python]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[python3]]></category>
            <category><![CDATA[organization]]></category>
            <dc:creator><![CDATA[Pratik Asija]]></dc:creator>
            <pubDate>Fri, 03 Feb 2023 12:31:05 GMT</pubDate>
            <atom:updated>2023-02-07T18:55:07.837Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>File handling is an important aspect of programming and is used to manipulate, store, and retrieve data from a computer’s file system. In this article, we will go over the basics of file handling in Python, including opening and reading files, writing to files, and appending data to files.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*xwgFcylgPxCPC2fQ" /><figcaption>Photo by <a href="https://unsplash.com/@mvdheuvel?utm_source=medium&amp;utm_medium=referral">Maarten van den Heuvel</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p><strong>Opening a file in Python</strong></p><p>To open a file in Python, we use the built-in function open(). The function takes two arguments: the name of the file and the mode in which the file should be opened. There are four modes:</p><ul><li><em>‘r’ — Read only mode (default)</em></li><li><em>‘w’ — Write mode</em></li><li><em>‘a’ — Append mode</em></li><li><em>‘x’ — Exclusive creation mode</em></li></ul><p>Here’s an example of opening a file in read mode:</p><pre>f = open(&quot;example.txt&quot;, &quot;r&quot;)</pre><p><strong>Reading a file in Python</strong></p><p>Once the file is opened, we can use several built-in functions to read the contents of the file.</p><ul><li>read(): This function reads the entire file and returns its contents as a string.</li></ul><pre>f = open(&quot;example.txt&quot;, &quot;r&quot;)<br>content = f.read()<br>print(content)<br>f.close()</pre><ul><li>readline(): This function reads a single line from the file and returns it as a string.</li></ul><pre>f = open(&quot;example.txt&quot;, &quot;r&quot;)<br>line = f.readline()<br>print(line)<br>f.close()</pre><ul><li>readlines(): This function reads all the lines in the file and returns them as a list of strings.</li></ul><pre>f = open(&quot;example.txt&quot;, &quot;r&quot;)<br>lines = f.readlines()<br>for line in lines:<br>    print(line)<br>f.close()</pre><p><strong>Writing to a file in Python</strong></p><p>To write to a file in Python, we use the write() method. If the file does not exist, Python will create it. If the file exists and is opened in write mode, its contents will be overwritten. Here&#39;s an example:</p><pre>f = open(&quot;example.txt&quot;, &quot;w&quot;)<br>f.write(&quot;This is a new line of text.&quot;)<br>f.close()</pre><p><strong>Appending to a file in Python</strong></p><p>To append data to an existing file in Python, we use the a mode when opening the file. Here&#39;s an example:</p><pre>f = open(&quot;example.txt&quot;, &quot;a&quot;)<br>f.write(&quot;This is a new line of text added in append mode.&quot;)<br>f.close()</pre><p><strong>Closing a file in Python</strong></p><p>It is always a good practice to close a file after you are done working with it. To close a file in Python, we use the close() method. For example:</p><pre>f = open(&quot;example.txt&quot;, &quot;r&quot;)<br>content = f.read()<br>print(content)<br>f.close()</pre><p><strong>Using the </strong><strong>with statement</strong></p><p>The with statement is a convenient way to work with files in Python, as it automatically closes the file after the code block within the with statement has been executed. Here&#39;s an example:</p><pre>with open(&quot;example.txt&quot;, &quot;r&quot;) as f:<br>    content = f.read()</pre><p><em>In conclusion</em>, file handling is an important aspect of programming and Python makes it easy to perform file operations with its built-in functions and methods. Whether you need to read data from a file, write to a file, or append data to a file, the steps outlined in this article will help you get started. With a little practice and exploration, you’ll be able to handle files like a pro!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e9bc2c254ed1" width="1" height="1" alt=""><hr><p><a href="https://towardsdev.com/file-handling-in-python-e9bc2c254ed1">File Handling in Python</a> was originally published in <a href="https://towardsdev.com/">Towards Dev</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building a Web App: Django and PostgreSQL]]></title>
            <link>https://towardsdev.com/building-a-web-app-django-and-postgresql-aa3d68b3ca0f?source=rss-a46220a9b893------2</link>
            <guid isPermaLink="false">https://medium.com/p/aa3d68b3ca0f</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[postgres]]></category>
            <category><![CDATA[django]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Pratik Asija]]></dc:creator>
            <pubDate>Sun, 29 Jan 2023 08:21:13 GMT</pubDate>
            <atom:updated>2023-02-10T19:38:49.661Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>I have already introduced to Django in my previous article, do check it out. This article is mainly focused on using <strong>PostgreSQL</strong> alongside <strong>Django</strong>. PostgreSQL, often simply “Postgres,” is an open-source relational database management system (RDBMS) that emphasizes extensibility and SQL compliance. It was originally developed at the <strong>University of California, Berkeley</strong> in the 1980s and has since become one of the most popular open-source databases in the world.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*pOVZp443U-hph8h2" /><figcaption>Photo by <a href="https://unsplash.com/@writecodenow?utm_source=medium&amp;utm_medium=referral">Boitumelo Phetla</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>First, we will start by installing Django and PostgreSQL. We can do this using pip and a package manager. In the terminal, run the following command to install Django:</p><pre>pip install django</pre><p>Then, run the following command to install PostgreSQL:</p><pre>sudo apt-get install postgresql postgresql-contrib libpq-dev python3-dev</pre><p>The last two commands are optional, but useful if you are going to use the <em>psycopg2</em> package to connect to postgres.</p><p>Next, we will create a new Django project. In this example, we will call our project “myproject”. In the terminal, navigate to the directory where you want to create the project and run the following command:</p><pre>django-admin startproject myproject</pre><p>This will create a new directory called “myproject” that contains the basic file structure for a Django project, which includes manage.py, settings.py, and urls.py files.</p><p>We will then create a new app within our project. This app will handle all the functionality for our application. We will call it “myapp”. In the terminal, navigate to the “myproject” directory and run the following command:</p><pre>python manage.py startapp myapp</pre><p>This will create a new directory called “myapp” within the “myproject” directory that contains the basic file structure for a Django app.</p><p>Next, we need to configure our project to use PostgreSQL as the database. In the settings.py file located in the “myproject” directory, we will set the DATABASES configuration to use the ‘django.db.backends.postgresql’ engine and provide the necessary credentials for connecting to the database.</p><pre>DATABASES = {<br>    &#39;default&#39;: {<br>        &#39;ENGINE&#39;: &#39;django.db.backends.postgresql&#39;,<br>        &#39;NAME&#39;: &#39;mydatabase&#39;,<br>        &#39;USER&#39;: &#39;mydatabaseuser&#39;,<br>        &#39;PASSWORD&#39;: &#39;mypassword&#39;,<br>        &#39;HOST&#39;: &#39;127.0.0.1&#39;,<br>        &#39;PORT&#39;: &#39;5432&#39;,<br>    }<br>}</pre><p>In this example, the database name is “mydatabase”, the database user is “mydatabaseuser”, and the password is “mypassword”. Make sure to change these values to match your own PostgreSQL installation.</p><p>Before we proceed with the next step, we have to create a database in <em>postgres</em>, you can use <em>pgAdmin</em> or command line to create it.You can use the following command to connect to <em>postgres</em> and create a new database</p><pre>sudo -u postgres psql</pre><p>then type the following command</p><pre>create database mydatabase;</pre><p>Now, we will install the <em>psycopg2</em> package using pip, which will allow us to connect to the PostgreSQL database. In the terminal, run the following command:</p><pre>pip install psycopg2</pre><p>We will then create the necessary tables in the database by running the following command:</p><pre>python manage.py makemigrations<br>python manage.py migrate</pre><p>This will create the necessary database tables based on the models defined in your project.</p><p>Next, we can start adding views and templates to our application. We will create a new file called <em>views.py</em> within the “myapp” directory, and use the Django views module to handle the logic for our application. Here’s an example of a simple view that returns a “Hello, World!” message:</p><pre>from django.shortcuts import render<br>from django.http import HttpResponse</pre><pre>def hello(request):<br>    return HttpResponse(&quot;Hello, World!&quot;)</pre><p>We will then create a new file called urls.py within the “myapp” directory, and use the Django URL dispatcher to map URLs to views. Here’s an example of how we would map the “/hello” URL to the hello view we just created:</p><pre>from django.urls import path<br>from . import views</pre><pre>urlpatterns = [<br>    path(&#39;hello/&#39;, views.hello, name=&#39;hello&#39;),<br>]</pre><p>We will then include the URLs for our app in the main “myproject” urls.py file, so that they can be accessed from the application. Here’s an example of how we would do this:</p><pre>from django.contrib import admin<br>from django.urls import include, path</pre><pre>urlpatterns = [<br>    path(&#39;&#39;, include(&#39;myapp.urls&#39;)),<br>    path(&#39;admin/&#39;, admin.site.urls),<br>]</pre><p>Finally, we will create a new directory called “templates” within the “myapp” directory, and create an HTML template called “hello.html” that will be rendered when the “/hello” URL is accessed. Here’s an example of what the “hello.html” file might look like:</p><pre>&lt;html&gt;<br>&lt;body&gt;<br>    &lt;h1&gt;{{ message }}&lt;/h1&gt;<br>&lt;/body&gt;<br>&lt;/html&gt;</pre><p>And we will update our views.py file to render this template instead of returning a response</p><pre>from django.shortcuts import render</pre><pre>def hello(request):<br>    return render(request, &#39;hello.html&#39;, {&#39;message&#39;: &#39;Hello, World!&#39;})</pre><p>You can now run the development server by running the following command:</p><pre>python manage.py runserver</pre><p>And you can access the application by visiting <a href="http://127.0.0.1:8000/hello"><em>http://127.0.0.1:8000/hello</em></a> in your web browser.</p><p>These are the basic steps for creating a web application using Django and PostgreSQL. You can now start building out the functionality for your application by adding <em>models, views, templates, and other components.</em></p><p>Next, we can start adding views and templates to our application. We will create a new file called views.py within the “myapp” directory, and use the Django views module to handle the logic for our application. Here’s an example of a simple view that returns a “Hello, World!” message:</p><pre>from django.shortcuts import render<br>from django.http import HttpResponse</pre><pre>def hello(request):<br>    return HttpResponse(&quot;Hello, World!&quot;)</pre><p>We will then create a new file called urls.py within the “myapp” directory, and use the Django URL dispatcher to map URLs to views. Here’s an example of how we would map the “/hello” URL to the hello view we just created:</p><pre>from django.urls import path<br>from . import views</pre><pre>urlpatterns = [<br>    path(&#39;hello/&#39;, views.hello, name=&#39;hello&#39;),<br>]</pre><p>We will then include the URLs for our app in the main “myproject” urls.py file, so that they can be accessed from the application. Here’s an example of how we would do this:</p><pre>from django.contrib import admin<br>from django.urls import include, path</pre><pre>urlpatterns = [<br>    path(&#39;&#39;, include(&#39;myapp.urls&#39;)),<br>    path(&#39;admin/&#39;, admin.site.urls),<br>]</pre><p>Finally, we will create a new directory called “templates” within the “myapp” directory, and create an HTML template called “hello.html” that will be rendered when the “/hello” URL is accessed. Here’s an example of what the “hello.html” file might look like:</p><pre>&lt;html&gt;<br>&lt;body&gt;<br>    &lt;h1&gt;{{ message }}&lt;/h1&gt;<br>&lt;/body&gt;<br>&lt;/html&gt;</pre><p>And we will update our <em>views.py</em> file to render this template instead of returning a response</p><pre>from django.shortcuts import render</pre><pre>def hello(request):<br>    return render(request, &#39;hello.html&#39;, {&#39;message&#39;: &#39;Hello, World!&#39;})</pre><p>You can now run the development server by running the following command</p><pre>python manage.py runserver</pre><p>And you can access the application by visiting http://127.0.0.1:8000/hello in your web browser.</p><p>These are the basic steps for creating a web application using Django and PostgreSQL. You can now start building out the functionality for your application by adding models, views, templates, and other components.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=aa3d68b3ca0f" width="1" height="1" alt=""><hr><p><a href="https://towardsdev.com/building-a-web-app-django-and-postgresql-aa3d68b3ca0f">Building a Web App: Django and PostgreSQL</a> was originally published in <a href="https://towardsdev.com/">Towards Dev</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Django for the modern web: Building a RESTAPI]]></title>
            <link>https://medium.com/@asijapratik/django-for-the-modern-web-building-a-restapi-a6ab0cd71275?source=rss-a46220a9b893------2</link>
            <guid isPermaLink="false">https://medium.com/p/a6ab0cd71275</guid>
            <category><![CDATA[python-programming]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[rest-api]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[django]]></category>
            <dc:creator><![CDATA[Pratik Asija]]></dc:creator>
            <pubDate>Wed, 25 Jan 2023 07:01:24 GMT</pubDate>
            <atom:updated>2023-01-25T12:47:50.514Z</atom:updated>
            <content:encoded><![CDATA[<blockquote><strong>RESTful APIs</strong> have become an essential part of modern web development. They allow for easy communication between different systems and platforms, and are a great way to provide access to your data and functionality to third-party developers.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*B1PJS98lghmioZBt" /><figcaption>Photo by <a href="https://unsplash.com/@faisaldada?utm_source=medium&amp;utm_medium=referral">Faisal</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>In this article, we will go through the process of building a RESTful API using Django, one of the most popular web frameworks for Python.</p><p><strong>Step 1: Setting up a Django Project</strong></p><p>The first step in building a Django-based REST API is to create a new Django project. To do this, you will need to have Django installed on your system. You can install it using pip by running the following command:</p><pre>pip install django</pre><p>Once you have Django installed, you can create a new project by running the following command:</p><pre>django-admin startproject myproject</pre><p>This will create a new directory called <em>myproject</em>, which will contain the basic structure of a Django project.</p><p><strong>Step 2: Creating a Django App</strong></p><p>The next step is to create a new app within our project. An app is a self-contained module within a Django project that can contain models, views, and templates. To create a new app, navigate to the root of your project directory and run the following command:</p><pre>python manage.py startapp myapp</pre><p>This will create a new directory called <em>myapp</em>, which will contain the basic structure of a Django app.</p><p><strong>Step 3: Defining Models</strong></p><p>In this step, we will define the models for our API. Models are Python classes that define the structure of the data that our API will work with. In this example, we will create a simple model called “Task” that has a title and a description.</p><p>To define the Task model, open the myapp/models.py file and add the following code:</p><pre>from django.db import models</pre><pre>class Task(models.Model):<br>    title = models.CharField(max_length=255)<br>    description = models.TextField()</pre><p>This defines a new model called Task that has two fields, title and description. The CharField is used for short strings, and the TextField is used for longer strings.</p><p><strong>Step 4: Creating Serializers</strong></p><p>In this step, we will create serializers for our models. <em>Serializers</em> are used to convert the data from our models into a format that can be easily rendered into JSON or XML. We will use the Django REST framework to create our serializers.</p><p>To install the Django REST framework, run the following command:</p><pre>pip install djangorestframework</pre><p>Once the framework is installed, create a new file called serializers.py in the <em>myapp</em> directory, and add the following code:</p><pre>from rest_framework import serializers<br>from .models import Task</pre><pre>class TaskSerializer(serializers.ModelSerializer):<br>    class Meta:<br>        model = Task<br>        fields = (&#39;id&#39;, &#39;title&#39;, &#39;description&#39;)</pre><p>This creates a new serializer class called <em>TaskSerializer</em> that is based on the Task model we defined earlier. The fields attribute is used to specify which fields from the model should be included in the serialized data.</p><p><strong>Step 5: Creating Views</strong></p><p>In this step, we will create views for our API. Views handle the logic for handling incoming requests and returning responses. We will use the generic views provided by the Django REST framework to handle the common CRUD (Create, Retrieve, Update, Delete) operations.</p><pre>from rest_framework import generics<br>from .models import Task<br>from .serializers import TaskSerializer</pre><pre>class TaskList(generics.ListCreateAPIView):<br>    queryset = Task.objects.all()<br>    serializer_class = TaskSerializer</pre><pre>class TaskDetail(generics.RetrieveUpdateDestroyAPIView):<br>    queryset = Task.objects.all()<br>    serializer_class = TaskSerializer</pre><p>This code defines two views, <em>TaskList</em> and <em>TaskDetail</em>, that handle the List and Retrieve, Update and Delete operations respectively. The views inherit from the generic views provided by the Django REST framework and use the TaskSerializer and the Task model to handle the data.</p><p><strong>Step 6: Setting up URL routing</strong></p><p>In this step, we will set up <em>URL routing</em> for our API. URL routing maps URLs to views, so that when a user visits a certain URL, the corresponding view is called.</p><p>Open the myproject/urls.py file and add the following code:</p><pre>from django.urls import path, include<br>from rest_framework.routers import DefaultRouter<br>from myapp.views import TaskList, TaskDetail</pre><pre>router = DefaultRouter()<br>router.register(r&#39;tasks&#39;, TaskList, basename=&#39;task&#39;)</pre><pre>urlpatterns = [<br>    path(&#39;&#39;, include(router.urls)),<br>]</pre><p>This code creates a new router object and register the TaskList view to handle the tasks URL. The include function is used to include the URLs from the router in the main URL patterns.</p><p><strong>Step 7: Testing the API</strong></p><p>Now that we have set up our API, we can test it by starting the development server:</p><pre>python manage.py runserver</pre><p>And then visiting <a href="http://localhost:8000/tasks/">http://localhost:8000/tasks/</a> in the browser. You should see a JSON response of all the tasks, and you can also test other <strong>CRUD </strong>operations by visiting the appropriate url.</p><p>That concludes the process of building a basic REST API using Django. This example demonstrates the basic structure of a Django-based REST API, but it can be easily expanded to include more models, views, and functionality. Some next steps would be to add authentication and permissions to the API, to handle different types of requests and responses, and to create a more complex data model. Django REST framework also provides a lot of other features such as pagination, filtering, and throttling that can be used to improve the functionality of your API.</p><p>It’s important to note that building a REST API is just one of the many things that you can do with Django.<strong> Django is a powerful web framewor</strong>k that can be used for a wide variety of web development tasks such as building web applications, e-commerce sites, and content management systems. By understanding the basics of building a REST API with Django, you will be well on your way to becoming a proficient Django developer.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a6ab0cd71275" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Image and Video Processing in Python]]></title>
            <link>https://medium.com/@asijapratik/image-and-video-processing-in-python-7e78ba7ccf83?source=rss-a46220a9b893------2</link>
            <guid isPermaLink="false">https://medium.com/p/7e78ba7ccf83</guid>
            <category><![CDATA[tech-blog]]></category>
            <category><![CDATA[pillow]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[opencv]]></category>
            <category><![CDATA[image-processing]]></category>
            <dc:creator><![CDATA[Pratik Asija]]></dc:creator>
            <pubDate>Fri, 20 Jan 2023 08:21:47 GMT</pubDate>
            <atom:updated>2023-01-25T17:32:54.316Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*dHvsaBEANvgVY83_" /><figcaption>Photo by <a href="https://unsplash.com/fr/@mylene1708?utm_source=medium&amp;utm_medium=referral">Mylene Tremoyet</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Python is an awesome language, and its not just me who’s saying it. Since python is so easy to use and its become easier to write more and more libraries, adding functionality to python has become very easy. Python when developed already had a number of libraries working with it and with time it has become more and more easy to perform any kind of tasks using Python.</p><p>There are several libraries in Python that can be used for image and video processing. Some of the most popular ones include:</p><ol><li><strong>OpenCV (Open Source Computer Vision Library):</strong> OpenCV is one of the most widely used libraries for image and video processing in Python. It provides a wide range of functionalities including image enhancement, object detection, and video stabilization. It is written in C++ but has a Python interface, allowing developers to easily use its functionalities in their Python projects.</li><li><strong>scikit-image:</strong> scikit-image is an image processing library that provides a wide range of image processing algorithms. It includes image segmentation, feature extraction, and image registration. It is built on top of the popular libraries NumPy and SciPy.</li><li><strong>Pillow</strong>: Pillow is a fork of the Python Imaging Library (PIL) and provides a wide range of image processing capabilities. It is widely used for image file handling, image manipulation and image processing tasks.</li><li><strong>Imageio:</strong> Imageio is a library that provides an easy interface to read and write a wide range of image and video formats. It supports a variety of formats such as PNG, JPEG, TIFF, and many more.</li><li><strong>SimpleCV</strong>: SimpleCV is a wrapper for the OpenCV library, which makes it easy to use for beginners. It offers a simple, consistent interface for common image processing tasks such as image manipulation, feature extraction, and image analysis.</li><li><strong>Mahotas</strong>: Mahotas is a computer vision library for Python. It provides functions for image processing and computer vision tasks such as image thresholding, morphological operations, and feature extraction.</li><li><strong>scikit-video</strong>: scikit-video is a video processing library that provides a wide range of video processing algorithms. It includes video compression, video stabilization and feature extraction.</li><li><strong>moviepy:</strong> moviepy is a video editing library for Python. It allows you to create, edit, and compose videos using a simple and easy-to-use API.</li><li><strong>PyAV:</strong> PyAV is a Pythonic binding for FFmpeg, which provides an easy interface to handle audio and video files. It can be used to read, write, and stream audio and video files of various formats.</li><li><strong>OpenCV-Python-Tutorial-Geeksforgeeks:</strong> This library is a tutorial for OpenCV-Python and it contains a wide range of tutorials on image processing, object detection, and video processing.</li></ol><p>All these libraries have their own unique features and functionalities, and the best one to use would depend on the specific task you are trying to accomplish. OpenCV is a well-rounded library that is great for a variety of image and video processing tasks, while other libraries such as scikit-image and Pillow are more specialized for specific tasks.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7e78ba7ccf83" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>