Rajendra Dharmkar

Rajendra Dharmkar

160 Articles Published

Articles by Rajendra Dharmkar

160 articles

How to access Python objects within objects in Python?

Rajendra Dharmkar
Rajendra Dharmkar
Updated on 25-Mar-2026 250 Views

In Python, it's common to have objects within objects, creating nested data structures. To access objects within objects, you can use the dot notation, which allows you to chain attribute access. Basic Object Composition Let's start with a simple example where a Person class contains an Address object ? class Person: def __init__(self, name, age): self.name = name self.age = age self.address = Address("123 Main St", "Anytown", "USA") ...

Read More

How to insert a Python object in MySQL?

Rajendra Dharmkar
Rajendra Dharmkar
Updated on 25-Mar-2026 1K+ Views

To insert Python objects like tuples, lists, or dictionaries into a MySQL database, you need to establish a connection and use parameterized queries. This tutorial shows how to safely insert Python data structures into MySQL tables. Prerequisites First, install the PyMySQL module and ensure you have a MySQL database with an employee table ? pip install PyMySQL Create the employee table structure ? CREATE TABLE employee ( fname VARCHAR(50), lname VARCHAR(50), age INT, gender CHAR(1), ...

Read More

How to pass Drop Down Box Data to Python CGI script?

Rajendra Dharmkar
Rajendra Dharmkar
Updated on 24-Mar-2026 630 Views

Drop down boxes are useful HTML form elements when you have multiple options but only want to allow selection of one or two items. Here's how to pass dropdown data to a Python CGI script and process it server-side. HTML Form with Dropdown First, create an HTML form with a dropdown (select) element ? Maths Physics Chemistry This creates a dropdown with ...

Read More

How to pass Text Area Data to Python CGI script?

Rajendra Dharmkar
Rajendra Dharmkar
Updated on 24-Mar-2026 901 Views

The TEXTAREA element allows users to input multiline text data that can be processed by a Python CGI script. This is useful for forms that need to collect longer text content like comments, descriptions, or messages. HTML Form with TEXTAREA Here is the HTML code for creating a form with a TEXTAREA element ? Type your text here... The result of this code is the following form ? Type your text here... Submit Python CGI Script Below is the textarea.py script to handle ...

Read More

How to pass Radio Button Data to Python CGI script?

Rajendra Dharmkar
Rajendra Dharmkar
Updated on 24-Mar-2026 1K+ Views

Radio buttons allow users to select exactly one option from a group of choices. When working with CGI (Common Gateway Interface) in Python, you can easily retrieve and process radio button data using the cgi module. HTML Form with Radio Buttons Here is example HTML code for a form with two radio buttons − Maths Physics The result of this code is the following form − Maths Physics [Select Subject] Python CGI Script Below is radiobutton.py script to handle input given by web ...

Read More

How do we do a file upload using Python CGI Programming?

Rajendra Dharmkar
Rajendra Dharmkar
Updated on 24-Mar-2026 3K+ Views

To upload a file using Python CGI programming, the HTML form must have the enctype attribute set to multipart/form-data. The input tag with file type creates a "Browse" button that allows users to select files from their system. HTML Upload Form First, create an HTML form that allows file selection − File: This form displays a file selection interface − File: Choose file Upload Python CGI Upload Handler Here's ...

Read More

How to retrieve cookies in Python CGI Programming?

Rajendra Dharmkar
Rajendra Dharmkar
Updated on 24-Mar-2026 1K+ Views

Retrieving cookies in Python CGI programming allows you to access data stored in the user's browser. Cookies are stored in the CGI environment variable HTTP_COOKIE and can be parsed to extract individual values. Cookie Storage Format Cookies are stored in the HTTP_COOKIE environment variable in the following format − key1=value1;key2=value2;key3=value3.... Basic Cookie Retrieval Here's how to retrieve and parse cookies from the environment variable − #!/usr/bin/env python3 # Import modules for CGI handling import os import cgi # Check if cookies exist if 'HTTP_COOKIE' in os.environ: ...

Read More

How to setup cookies in Python CGI Programming?

Rajendra Dharmkar
Rajendra Dharmkar
Updated on 24-Mar-2026 920 Views

Cookies in Python CGI programming allow you to store small pieces of data on the client's browser. Setting cookies is straightforward − they are sent as HTTP headers before the Content-type field. Setting Basic Cookies Cookies are set using the Set-Cookie HTTP header. Here's how to set UserID and Password cookies ? #!/usr/bin/python3 print("Set-Cookie:UserID=XYZ;\r") print("Set-Cookie:Password=XYZ123;\r") print("Content-type:text/html\r\r") print("") print("Cookies have been set!") print("") Setting Cookies with Attributes You can specify additional attributes like expiration date, domain, and path for better cookie control ? #!/usr/bin/python3 print("Set-Cookie:UserID=XYZ;\r") print("Set-Cookie:Password=XYZ123;\r") print("Set-Cookie:Expires=Tuesday, 31-Dec-2025 23:12:40 GMT;\r") print("Set-Cookie:Domain=www.tutorialspoint.com;\r") ...

Read More

How do cookies work in Python CGI Programming?

Rajendra Dharmkar
Rajendra Dharmkar
Updated on 24-Mar-2026 653 Views

HTTP protocol is a stateless protocol, meaning it doesn't remember information between requests. For commercial websites, it's essential to maintain session information across different pages. For example, user registration may span multiple pages, requiring session data persistence. In many situations, using cookies is the most efficient method of remembering and tracking preferences, purchases, commissions, and other information required for better visitor experience or site statistics. How Cookies Work Your server sends data to the visitor's browser in the form of a cookie. The browser may accept the cookie and store it as a plain text record on ...

Read More

What is the difference between GET and POST in Python CGI Programming?

Rajendra Dharmkar
Rajendra Dharmkar
Updated on 24-Mar-2026 2K+ Views

In Python CGI Programming, the two primary methods for passing information from a web browser to a web server are GET and POST. Understanding their differences is crucial for web development security and functionality. GET Method 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. It produces a long string that appears in your browser's Location box. Never use GET ...

Read More
Showing 1–10 of 160 articles
« Prev 1 2 3 4 5 16 Next »
Advertisements