Server Side Programming Articles

Page 569 of 2109

Parsing XML with DOM APIs in Python

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

The Document Object Model (DOM) is a cross-language API from the World Wide Web Consortium (W3C) for accessing and modifying XML documents. Unlike SAX parsers that process XML sequentially, DOM loads the entire document into memory as a tree structure, allowing random access to any element. The DOM is extremely useful for random-access applications. SAX only allows you a view of one bit of the document at a time, while DOM provides complete access to the entire document structure simultaneously. Basic DOM Parsing Here is the easiest way to quickly load an XML document and create a ...

Read More

Multithreaded Priority Queue in Python

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

The Queue module in Python allows you to create thread-safe queue objects for multithreaded applications. A priority queue processes items based on their priority rather than insertion order, making it ideal for task scheduling and resource management. Queue Methods The Queue module provides several methods to control queue operations ? get() − Removes and returns an item from the queue put() − Adds an item to the queue qsize() − Returns the number of items currently in the queue empty() − Returns True if queue is empty; otherwise, False full() − Returns True if queue is ...

Read More

Sending an HTML e-mail using Python

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

When you send a text message using Python, all the content is treated as simple text. Even if you include HTML tags in a text message, it is displayed as simple text and HTML tags will not be formatted according to HTML syntax. However, Python provides the option to send an HTML message as actual HTML content. While sending an email message, you can specify a MIME version, content type and character set to send an HTML email that renders properly in email clients. Basic HTML Email Structure To send HTML email, you need to set the ...

Read More

Disconnecting Database in Python

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

When working with databases in Python, it's essential to properly close connections to free up resources and ensure data integrity. The close() method is used to disconnect from the database. Basic Syntax To disconnect a database connection, use the close() method − connection.close() Complete Example with SQLite Here's a complete example showing how to connect to a database, perform operations, and properly close the connection − import sqlite3 # Create connection connection = sqlite3.connect(':memory:') # In-memory database for demo cursor = connection.cursor() # Create a table and insert ...

Read More

Commit & RollBack Operation in Python

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

Database transactions in Python require careful management of commit and rollback operations. These operations ensure data integrity by allowing you to either save changes permanently or undo them completely. Understanding Transactions A transaction is a sequence of database operations that must be completed as a single unit. If any operation fails, the entire transaction can be rolled back to maintain data consistency. COMMIT Operation The commit() method finalizes all changes made during the current transaction. Once committed, changes become permanent and cannot be reverted. Example import sqlite3 # Connect to database conn ...

Read More

Database INSERT Operation in Python

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

The INSERT operation is used to add new records to a database table in Python. This operation requires establishing a database connection, preparing SQL statements, and handling transactions properly. Basic INSERT Statement The following example executes an SQL INSERT statement to create a record in the EMPLOYEE table ? #!/usr/bin/python import MySQLdb # Open database connection db = MySQLdb.connect("localhost", "testuser", "test123", "TESTDB") # prepare a cursor object using cursor() method cursor = db.cursor() # Prepare SQL query to INSERT a record into the database sql = """INSERT INTO EMPLOYEE(FIRST_NAME, ...

Read More

How To Raise a "File Download" Dialog Box in Python?

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

Sometimes, you want to provide a download link that triggers a "File Download" dialog box instead of displaying the file content directly in the browser. This can be achieved by setting specific HTTP headers that instruct the browser to treat the response as a downloadable file. Basic File Download Example Here's how to create a simple file download response using Python CGI ? #!/usr/bin/python3 import sys # Set HTTP headers for file download print("Content-Type: application/octet-stream; name="example.txt"") print("Content-Disposition: attachment; filename="example.txt"") print() # Empty line to separate headers from content # Read and output file ...

Read More

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 702 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 716 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
Showing 5681–5690 of 21,090 articles
« Prev 1 567 568 569 570 571 2109 Next »
Advertisements