<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Mohammad T. Khan</title>
    <description>The latest articles on DEV Community by Mohammad T. Khan (@lcg_2021).</description>
    <link>https://dev.to/lcg_2021</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1739106%2F63cfd793-85ef-42f8-922b-1ece39f25c6f.png</url>
      <title>DEV Community: Mohammad T. Khan</title>
      <link>https://dev.to/lcg_2021</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/lcg_2021"/>
    <language>en</language>
    <item>
      <title>Getting Started with SQLAlchemy</title>
      <dc:creator>Mohammad T. Khan</dc:creator>
      <pubDate>Mon, 05 Aug 2024 17:32:00 +0000</pubDate>
      <link>https://dev.to/lcg_2021/getting-started-with-sqlalchemy-ie7</link>
      <guid>https://dev.to/lcg_2021/getting-started-with-sqlalchemy-ie7</guid>
      <description>&lt;p&gt;&lt;strong&gt;What is SQLAlchemy?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Think of SQLAlchemy as your friendly neighborhood guide to databases. It lets you chat with your databases using Python instead of complex SQL queries. It’s like translating a foreign language into your mother tongue!.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key Features&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;SQLAlchemy has two main features:&lt;/p&gt;

&lt;p&gt;Core: Direct database interaction using SQL expressions. This is like the engine of a car, powering direct interactions with your database using SQL.&lt;/p&gt;

&lt;p&gt;ORM (Object-Relational Mapping): Maps Python classes to database tables for simpler database manipulation. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Setting Up Your Environment&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;First, install SQLAlchemy with pip:&lt;br&gt;
&lt;/p&gt;

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

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Crafting Your First Model&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Models are blueprints of your database tables. Here’s a simple User model to get you started:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from sqlalchemy import create_engine, Column, Integer, String
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker

Base = declarative_base()

class User(Base):
    __tablename__ = 'users'
    id = Column(Integer, primary_key=True)
    name = Column(String)
    age = Column(Integer)

engine = create_engine('sqlite:///mydatabase.db')
Base.metadata.create_all(engine)
Session = sessionmaker(bind=engine)
session = Session()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Adding and Finding Users&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Here's how to add a new user and find existing ones with ease:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Adding a new user
new_user = User(name='John Doe', age=28)
session.add(new_user)
session.commit()

# Querying users
users = session.query(User).all()
for user in users:
    print(user.name, user.age)


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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Why SQLAlchemy Rocks&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Using SQLAlchemy can feel like having a magic wand for your database tasks because:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It cuts down on complex SQL code.&lt;/li&gt;
&lt;li&gt;It keeps your code clean and readable.&lt;/li&gt;
&lt;li&gt;It works with different database types seamlessly.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;SQLAlchemy is a fantastic tool for Python developers looking to interact with databases efficiently. It's both powerful and flexible, making database tasks simpler and your code cleaner.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>How to Set Up a Flask Environment</title>
      <dc:creator>Mohammad T. Khan</dc:creator>
      <pubDate>Sat, 20 Jul 2024 08:46:53 +0000</pubDate>
      <link>https://dev.to/lcg_2021/how-to-set-up-a-flask-environment-24l3</link>
      <guid>https://dev.to/lcg_2021/how-to-set-up-a-flask-environment-24l3</guid>
      <description>&lt;p&gt;&lt;strong&gt;Introduction&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Flask is a lightweight and versatile web framework for Python that makes it easy to create web applications. Whether you're building a simple web page or a complex, database-driven website, Flask provides the tools you need while keeping the core functionality minimal. This allows you to scale your application as needed without unnecessary overhead&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Setting Up Your Flask Environment&lt;/strong&gt;&lt;br&gt;
Before we start coding, we need to set up our development environment. Here are the steps&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Install Python&lt;/strong&gt;&lt;br&gt;
Make sure you have Python installed on your machine. You can download it from the official Python website here.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Install Flask&lt;/strong&gt;&lt;br&gt;
Use pip, the Python package installer, to install Flask. Open your terminal or command prompt and run:&lt;br&gt;
&lt;/p&gt;

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

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;3. Create a Project Directory&lt;/strong&gt;&lt;br&gt;
Create a directory for your Flask project and navigate into it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mkdir flask_app
cd flask_app

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;4. Create a Virtual Environment&lt;/strong&gt;&lt;br&gt;
It's a good practice to use a virtual environment for your projects. This keeps your project dependencies isolated. Run the following commands to create and activate a virtual environment:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;python -m venv venv
source venv/bin/activate 
#or
venv\Scripts\activate

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Creating Your First Flask Application&lt;/strong&gt;&lt;br&gt;
Now that our environment is set up, let's create a simple Flask application.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Create the Application File&lt;/strong&gt;&lt;br&gt;
Inside your project directory, create a file named app.py. This file will contain our Flask application code.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Write Your Flask Application&lt;/strong&gt;&lt;br&gt;
Open app.py in your text editor and add the following code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from flask import Flask

app = Flask(__name__)

@app.route('/')
def home():
    return "Hello, Flask!"

if __name__ == '__main__':
    app.run(debug=True)

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;3. Run Your Application&lt;/strong&gt;&lt;br&gt;
Save the file and run the application by executing the following command in your terminal:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;python app.py

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

&lt;/div&gt;



&lt;p&gt;If everything is set up correctly, you should see output indicating that the Flask server is running. Open your web browser and go to &lt;a href="http://127.0.0.1:5000/" rel="noopener noreferrer"&gt;http://127.0.0.1:5000/&lt;/a&gt;. You should see "Hello, Flask!" displayed on the page.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br&gt;
In this post, we've introduced Flask, a lightweight web framework for Python. We covered the basics of setting up a Flask project and creating a simple web application. Flask's simplicity and flexibility make it an excellent choice for both beginners and experienced developers.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Python Lists Unpacked: Your Everyday Guide to Using Lists</title>
      <dc:creator>Mohammad T. Khan</dc:creator>
      <pubDate>Sat, 06 Jul 2024 16:42:07 +0000</pubDate>
      <link>https://dev.to/lcg_2021/python-lists-unpacked-your-everyday-guide-to-using-lists-493c</link>
      <guid>https://dev.to/lcg_2021/python-lists-unpacked-your-everyday-guide-to-using-lists-493c</guid>
      <description>&lt;p&gt;Today, I intend to share one of Python’s most simple yet powerful tools: lists. &lt;br&gt;
Whether you’re just starting your coding journey or you've been coding in Python for a while, understanding lists and how to wield them can make your life a whole lot easier&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What Exactly Are Python Lists?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Just as you are with your shopping list, think of yourself at a food market. You’ve got fruits, vegetables, snacks, and maybe some indulgent treats (of course, we all want something like this, don’t we?). In Python, a list is doing the same job. It's a collection of things, which are stored in one place, they are there and can - as a result - be added or removed. Here is an example of what it looks like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;my_shopping_list = ['apples', 'bananas', 'carrots', 'doughnuts']
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Isn’t it simple? But don’t be deceived by their simplicity – lists can perform miracles.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Making and Extracting Lists&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Everything is very easy where you’ve made a list. You should just take those things that should be on your list and include them in square brackets; the list is yours in a second. A list can be generated like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;my_friends = ['Alice', 'Bob', 'Charlie']
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, let’s say you want to know who is at the top of your friends’ list. To access any element within a list we use its index number. Mind that Python starts indexing from zero so that the first element would be indexed 0:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;first_friend = my_friends[0] # This will be ‘Alice’
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Adding and Removing Elements&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Have a new pal? No worries. Use the append() method to add them at the end of the list:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;my_friends.append('Diana')
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Oh no, made an error? Do you have to eliminate someone from this list? It’s possible to remove any value from a list through remove():&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;my_friends.remove('Bob')
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Alternatively, when you want to pop off an item at the end, simply use pop():&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;last_friend = my_friends.pop() # Removes and returns 'Diana' (if she was the last)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Why Use Lists?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Lists aren’t limited to merely saving a bunch of names or things. They are vital for Python data handling. Data iteration, object differentiation or mere programming organization can be facilitated using lists.&lt;/p&gt;

&lt;p&gt;They also are what leads us to more complex data structures like arrays (in libraries like NumPy). These are necessary for data analysis and scientific computing.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In brief, there is flexibility in using python lists for programming in different ways as they’re simple and helpful tools. Beginning with managing little variable collections up to working on large datasets, mastering all that lists stand will help significantly on your coding journey.&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
