Hafeezul Kareem

Hafeezul Kareem

259 Articles Published

Articles by Hafeezul Kareem

Page 24 of 26

Add the slug field inside Django Model

Hafeezul Kareem
Hafeezul Kareem
Updated on 21-Sep-2020 510 Views

In this tutorial, we are going to learn about the SlugField in Django.SlugFieldSlugField is a way to generate a URL using the data which we already have. You can generate URL using your title of the post or page. Let's see one detailed example.Let's say we have an article with name This is from Tutorialspoint with id = 5. Then we can have URL as www.tutorialspoint.com/posts/5/. It's difficult for the content writers to recognize the article with the previous URL. But, if you have a URL like www.tutorialspoint.com/this-isfrom-tutorialspoint, then it's easy for us to identify the piece. So, SlugField is ...

Read More

Taking multiple inputs from user in Python

Hafeezul Kareem
Hafeezul Kareem
Updated on 11-Jul-2020 1K+ Views

In this tutorial, we are going to learn how to take multiple inputs from the user in Python.The data entered by the user will be in the string format. So, we can use the split() method to divide the user entered data.Let's take the multiple strings from the user.Example# taking the input from the user strings = input("Enter multiple names space-separated:- ") # spliting the data strings = strings.split() # printing the data print(strings)OutputIf you run the above code, then you will get the following result.Enter multiple names space-separated:- Python JavaScript Django React ['Python', 'JavaScript', 'Django', 'React']What if we want ...

Read More

Take Matrix input from user in Python

Hafeezul Kareem
Hafeezul Kareem
Updated on 11-Jul-2020 9K+ Views

In this tutorial, we are going to learn how to take matric input in Python from the user. We can take input from the user in two different ways. Let's see two of them.Method 1Taking all numbers of the matric one by one from the user. See the code below.Example# initializing an empty matrix matrix = [] # taking 2x2 matrix from the user for i in range(2):    # empty row    row = []    for j in range(2):       # asking the user to input the number       # converts the input to ...

Read More

Structuring Python Programs

Hafeezul Kareem
Hafeezul Kareem
Updated on 11-Jul-2020 518 Views

In this tutorial, we are going to see some best practices for structuring the Python programs. Let's see one by oneUse a tab for indentationUsing a tab for indentation in the code make code more readable instead of using random spaces for multiple functions and methods. You can set the number of spaces for a tab in any code editors' settings.Example# example def sample(random): # statement 1 # statement 2 # ... return randomDon't write more than 79 characters in a lineWriting more than 79 characters in a line is not recommended Python. Avoid this by breaking line into multiple ...

Read More

SQL using Python

Hafeezul Kareem
Hafeezul Kareem
Updated on 11-Jul-2020 1K+ Views

In this tutorial, we are going to learn how to use SQL with Python using SQLite database. has a built-in module to connect with SQLite database. We are going to use sqlite3 module to connect Python and SQLite.We have to follow the below steps to connect the SQLite database with Python. Have a look at the steps and write the program.Import the sqlite3 module.Create a connection using the sqlite3.connect(db_name) the method that takes a database name is an argument. It creates one file if doesn't exist with the given name else it opens the file with the given name.Get the ...

Read More

Send SMS updates to mobile phone using python

Hafeezul Kareem
Hafeezul Kareem
Updated on 11-Jul-2020 2K+ Views

In this tutorial, we are going to learn how to send SMS in Python. We will be using Twilio for sending SMS.First of all, go the Twilio and create an account. You will get free trial account. And finish settings.We have to install a module called twilio to work with Twilio client. Install it with the following command.pip install twilioNow, go to the Twilio Documentation on how to send SMS using Twilio client. Or follow the steps to send the SMS.Import the twilio Client from twilio.rest.Get and store the account_sid and auth_token from the your Twilio account.Make instance of the ...

Read More

Python Grouped Flattening of list

Hafeezul Kareem
Hafeezul Kareem
Updated on 07-Jul-2020 223 Views

In this tutorial, we are going to write a program that flattens a list that contains sub-lists. Given number flatten the sublists until the given number index as parts. Let's see an example to understand it clearly.Inputlists = [[1, 2], [3, 4], [5, 6], [7, 8], [9, 10]] number = 2Output[[1, 2, 3, 4], [5, 6, 7, 8], [9, 10]]Let's see the steps to solve the problem.Initialize the list and number.Initialize an empty list.Iterate over the list with range(0, len(lists), number.Get the sublists using slicing lists[i:number].Iterate over the sublists and append the resultant list to the result list.Print the result.Example# ...

Read More

YouTube Media/Audio Download using Python - pafy

Hafeezul Kareem
Hafeezul Kareem
Updated on 02-Jul-2020 1K+ Views

In this article, we will see how to extract details about Youtube videos and download them in different formats using the pafy module. Head over to the link for official documentation.Install the pafy module using the following commandpip install pafyIf you run the above command, it will generate the following results on the successful installation of the module pafy.Collecting pafy Using cached https://files.pythonhosted.org/packages/b0/e8/3516f761558525b00d3eaf73744eed5c267db 20650b7b660674547e3e506/pafy-0.5.4-py2.py3-none-any.whl Installing collected packages: pafy Successfully installed pafy-0.5.4Check whether you can import the pafy module or not by running the following command.import pafyIf you found no errors then it's done. Otherwise install the following module to solve ...

Read More

Why importing star is a bad idea in python

Hafeezul Kareem
Hafeezul Kareem
Updated on 29-Jun-2020 560 Views

Importing all methods from a module in Python is a bad idea because of the following reasons.It is difficult to find a parent module of the method which we used in the programs.We are not allowed to create our functions with the names of methods.Let's see an example. Below we write a function called add in the sample.py.## sample.py file def add(a, b): return a + bExampleSave the above file in the same directory as below Python file.## let's assume we have module called sample from sample import * def add(*nums):    return sum(nums) print(add(1, 2, 3, 4, ...

Read More

Writing files in the background in Python

Hafeezul Kareem
Hafeezul Kareem
Updated on 12-Feb-2020 622 Views

In this tutorial, we will learn about the multi-threading in Python. It helps us to perform multiple tasks at a time. Python has a module called threading for multitasking.We see how it works by writing data to a file in the background while calculating the sum of elements in a list. Let's see the steps involved in the program.Import the threading module.Create a class by inheriting threading.Thread class.Write the file code inside the run method in the above class.Initialize the required data.Write the code to calculate the sum of numbers in a list.Example# importing the modules import threading # creating ...

Read More
Showing 231–240 of 259 articles
Advertisements