Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Articles by Mohd Mohtashim
Page 2 of 19
Passing Checkbox Data to CGI Program in Python
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 MorePassing Information Using POST Method in Python
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 MorePassing Information using GET method in Python
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 MoreCGI Environment Variables in Python
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 MoreSpecial Syntax with Parentheses in Python
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 MoreRegular Expression Examples in Python
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 MoreRegular Expression Patterns in Python
Regular expressions are patterns used to match character combinations in strings. In Python, most characters match themselves, except for special control characters (+ ? . * ^ $ ( ) [ ] { } | \) which have special meanings. You can escape these control characters by preceding them with a backslash. The following table lists the regular expression syntax available in Python ? Pattern Description Example ^ Matches beginning of line ^Hello matches "Hello world" $ Matches end of line world$ matches "Hello world" . Matches ...
Read MoreRegular Expression Modifiers in Python
Regular expression modifiers (also called flags) are optional parameters that control how pattern matching behaves. You can combine multiple modifiers using the bitwise OR operator (|) to customize the search behavior. Common Regular Expression Modifiers Modifier Name Description re.I IGNORECASE Performs case-insensitive matching re.M MULTILINE Makes ^ and $ match start/end of each line re.S DOTALL Makes dot (.) match any character including newline re.X VERBOSE Ignores whitespace and allows comments in patterns re.L LOCALE Uses locale-aware matching (deprecated) re.U UNICODE ...
Read MoreOverloading Operators in Python
In Python, you can customize how operators work with your custom classes through operator overloading. This is achieved by defining special methods (also called magic methods) in your class that correspond to specific operators. Suppose you have created a Vector class to represent two-dimensional vectors, what happens when you use the plus operator to add them? Most likely Python will yell at you. You could, however, define the __add__ method in your class to perform vector addition and then the plus operator would behave as per expectation ? Example class Vector: ...
Read MoreBase Overloading Methods in Python
Python provides special methods (also called magic methods or dunder methods) that you can override in your classes to customize their behavior. These methods allow your objects to work seamlessly with built-in functions and operators. Common Base Overloading Methods Sr.No. Method, Description & Sample Call 1 __init__(self [, args...])Constructor method called when creating an objectSample Call: obj = ClassName(args) 2 __del__(self)Destructor method called when object is garbage collectedSample Call: del obj 3 __repr__(self)Returns unambiguous string representation for developersSample Call: repr(obj) 4 __str__(self)Returns human-readable string representationSample ...
Read More