Python Articles

Page 676 of 855

File Upload Example in Python

SaiKrishna Tavva
SaiKrishna Tavva
Updated on 25-Mar-2026 10K+ Views

File upload in Python can be implemented using the CGI (Common Gateway Interface) environment. This involves creating an HTML form for file selection and a Python script to handle the server−side file processing. The file upload process consists of two main components: an HTML form that allows users to select files, and a Python CGI script that processes and saves the uploaded files to the server. Creating HTML Form for File Upload The HTML form uses to create a file selection field and for the upload button. The form must include enctype="multipart/form-data" to handle file ...

Read More

Passing Checkbox Data to CGI Program in Python

Mohd Mohtashim
Mohd Mohtashim
Updated on 25-Mar-2026 695 Views

Checkboxes are used when more than one option is required to be selected. In web forms, checkbox data is sent to CGI programs where it can be processed using Python's cgi module. HTML Form with Checkboxes Here is example HTML code for a form with two checkboxes − Maths Physics Form Output The result of this code is the following form − Maths Physics Select ...

Read More

Passing Information Using POST Method in Python

Mohd Mohtashim
Mohd Mohtashim
Updated on 25-Mar-2026 714 Views

The POST method is a more secure and reliable way to pass information to a CGI program compared to GET. Instead of appending data to the URL, POST sends information as a separate message through standard input, making it ideal for sensitive data and large forms. How POST Method Works Unlike GET method which appends data to the URL after a ?, POST method: Sends data as a separate message body Doesn't expose sensitive information in the URL Can handle larger amounts of data Provides better security for form submissions Example: CGI Script for ...

Read More

Passing Information using GET method in Python

Mohd Mohtashim
Mohd Mohtashim
Updated on 25-Mar-2026 2K+ Views

The GET method sends encoded user information appended to the page request. The page and the encoded information are separated by the ? character as follows − http://www.test.com/cgi-bin/hello.py?key1=value1&key2=value2 The GET method is the default method to pass information from browser to web server and it produces a long string that appears in your browser's Location box. Never use GET method if you have password or other sensitive information to pass to the server. The GET method has size limitation: only 1024 characters can be sent in a request string. The GET method sends information using ...

Read More

CGI Environment Variables in Python

Mohd Mohtashim
Mohd Mohtashim
Updated on 25-Mar-2026 2K+ Views

All CGI programs have access to environment variables that contain important information about the request, server, and client. These variables play an important role while writing any CGI program. Common CGI Environment Variables Variable Name Description CONTENT_TYPE The data type of the content. Used when the client is sending attached content to the server (e.g., file upload). CONTENT_LENGTH The length of the query information. Available only for POST requests. HTTP_COOKIE Returns the set cookies in the form of key-value pairs. HTTP_USER_AGENT Contains information about the ...

Read More

Special Syntax with Parentheses in Python

Mohd Mohtashim
Mohd Mohtashim
Updated on 25-Mar-2026 215 Views

Python regular expressions support special syntax using parentheses for advanced pattern matching. These parentheses provide functionality like comments, case-insensitive matching, and non-capturing groups. Comment Syntax Use (?#comment) to add comments within regex patterns without affecting the match ? import re pattern = r'R(?#This is a comment)uby' text = "Ruby programming" match = re.search(pattern, text) if match: print(f"Found: {match.group()}") else: print("No match found") Found: Ruby Case-Insensitive Flag Use (?i) to enable case-insensitive matching for the rest of the pattern ? ...

Read More

Regular Expression Examples in Python

Mohd Mohtashim
Mohd Mohtashim
Updated on 25-Mar-2026 392 Views

Regular expressions (regex) are powerful tools for pattern matching and text processing in Python. The re module provides functions to work with regular expressions, allowing you to search, match, and manipulate text based on specific patterns. Literal Characters Literal characters in regex match themselves exactly. Here's how to use basic literal matching ? import re text = "python is awesome" pattern = "python" match = re.search(pattern, text) if match: print(f"Found: '{match.group()}'") else: print("Not found") Found: 'python' Character Classes Character classes ...

Read More

Largest Number in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 634 Views

Finding the largest number from a list of non-negative integers requires arranging them in a specific order. For example, given [10, 2], the largest number would be 210, not 102. The key insight is to sort numbers based on which arrangement produces a larger concatenated result. We compare two numbers by checking if x + y is greater than y + x as strings. Algorithm Steps Convert all numbers to strings Sort using a custom comparator that checks concatenated results Join the sorted strings and handle edge cases Implementation Let us see the ...

Read More

Binary Tree Inorder Traversal in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 3K+ Views

Binary tree inorder traversal visits nodes in the order: left subtree, root, right subtree. This article demonstrates how to perform inorder traversal iteratively using a stack instead of recursion. 10 5 15 2 7 20 ...

Read More

Decode Ways in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 25-Mar-2026 1K+ Views

Suppose we have a message containing letters from A to Z that is being encoded to numbers using the following mapping − 'A' → 1, 'B' → 2 ... 'Z' → 26. Given a non-empty string containing only digits, we need to find in how many ways that string can be decoded. For example, if the string is "12", it can be decoded as "AB" (1, 2) or "L" (12), so there are two possible ways. Algorithm Approach We will solve this using dynamic programming with the following steps ? Create a DP array where ...

Read More
Showing 6751–6760 of 8,549 articles
« Prev 1 674 675 676 677 678 855 Next »
Advertisements