Found 27104 Articles for Server Side Programming

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

Rajendra Dharmkar
Updated on 16-Jun-2020 12:31:23

2K+ Views

GET and POST MethodsYou must have come across many situations when you need to pass some information from your browser to web server and ultimately to your CGI Program. Most frequently, browser uses two methods two pass this information to web server. These methods are GET Method and POST Method.Passing Information using GET methodThe GET method sends the 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=value2The GET method is the default method to pass information from browser to web server and it produces a long ... Read More

What are important HTTP headers to be frequently used in Python CGI Programming?

Rajendra Dharmkar
Updated on 16-Jun-2020 12:25:28

266 Views

HTTP HeaderThe line Content-type:text/html\r\r is part of HTTP header which is sent to the browser to understand the content. All the HTTP header will be in the following form −HTTP Field Name − Field ContentFor ExampleContent-type − text/html\r\rThere are few other important HTTP headers, which we will use frequently in our CGI Programming.     Sr.No.HeaderDescription1Content-type:A MIME string defining the format of the file being returned. Example is Content-type:text/html2Expires: DateThe date the information becomes invalid. It is used by the browser to decide when a page needs to be refreshed. A valid date string is in the format 01 Jan 1998 ... Read More

What Content-type is required to write Python CGI program?

Rajendra Dharmkar
Updated on 30-Jul-2019 22:30:21

268 Views

If we run simple scripts like hello.py, its output is written on the STDOUT file, i.e., screen. There is one important and extra feature available which is the first line to be printed Content-type:text/html\r\r. This line is sent back to the browser and it specifies the content type to be displayed on the browser screen.We can write advanced CGI programs using Python. This script can interact with any other external system and even exchange information with RDBMS.

What are the modules required for CGI programming in Python?

Rajendra Dharmkar
Updated on 16-Jun-2020 12:21:40

150 Views

Python's cgi module is usually the starting place in writing CGI programs in Python. The main purpose of the cgi module is to extract the values passed to a CGI program from an HTML form. Mostly one interacts with CGI applications through an HTML form. One fills out some values in the form that specify details of the action to be performed, then call on the CGI to perform its action using your specifications.You may include many input fields within an HTML form which can be of a number of different types (text, checkboxes, picklists, radio buttons, etc.).Your Python script ... Read More

How to flatten a shallow list in Python?

Gireesha Devara
Updated on 24-Aug-2023 14:26:23

927 Views

Flattening a shallow list means converting a nested list into a simple single dimensional list. In other words, converting a multidimensional list into a one-dimensional list. The process of flattening can be performed by using different techniques like nested for loops, list comprehensions, list concatenation, and by using built-in functions. In this article, we will discuss a few techniques to flatten a shallow python list. Using nested for loop By using nested for loop and list.append() method we can flatten the shallow list. Let’s have a look and see how this can be done in a program. Example This simple ... Read More

How to clone or copy a list in Python?

Gireesha Devara
Updated on 24-Aug-2023 13:32:04

789 Views

The list in Python is a sequence data type which is used to store various types of data. A list is created by placing each data element inside square brackets [] and these are separated by commas. In Python, assignment operator doesn’t create a new object, rather it gives another name to already existing object. This can be verified by id() function >>> L1 = [1, 2, 3, 4] >>> L2 = L1 >>> id(L1) 185117137928 >>> id(L2) 185117137928 There are various ways of cloning/copying a list in python. In this article, we will discuss some of them. Using ... Read More

How can I convert a Python tuple to string?

Gireesha Devara
Updated on 24-Aug-2023 13:30:09

6K+ Views

A tuple is a collection of objects which ordered and immutable. Tuples are sequences, just like lists. The differences between tuples and lists are, the tuples cannot be changed unlike lists and tuples use parentheses, whereas lists use square brackets. There are three different ways we can convert a python tuple to string. Using a for loop. Using the python join() method Using the functool.reduce() method Using the for loop In python, we can easily iterate the tuple elements using the for loop, then we will append/add each element to the string object. In this below example we ... Read More

What is the difference between dict.items() and dict.iteritems() in Python?

Pythonic
Updated on 30-Jul-2019 22:30:21

236 Views

In Python 2.x, both methods are available, but in Python 3.x iteritems() is deprecated. As far as Python 2.x is concerned, items() method of dictionary object returns list of two element tuples, each tuple containing key and value. On the other hand iteritems() is a generator which provides an iterator for items in a dictionary >>> d = {'1': 1, '2': 2, '3': 3} >>> d.items() [(1, 1), (2, 2), (3, 3)] >>> for i in d.iteritems(): print i ('1', 1) ('2', 2) ('3', 3) In Python 3, items() method behaves ... Read More

How can I iterate through two lists in parallel in Python?

Gireesha Devara
Updated on 24-Aug-2023 13:28:07

611 Views

In Python, using a for loop is common to iterate a single data structure like list, but what if we need to iterate two/multiple lists parallelly?. In this article we will see different ways to iterate two/multiple lists parallelly. By using range() function, we can iterate the two lists parallelly. Lets see the below examples and how we are going to iterate two lists in python. Using the for loop If length of the two lists are same Assuming that both lists have the same length, here we are using the len() method to get the length of ... Read More

How to convert a String representation of a Dictionary to a dictionary in Python?

Gireesha Devara
Updated on 24-Aug-2023 13:24:45

6K+ Views

To convert a string represented dictionary to an original dictionary we can use built-in functions like eval(), json.load(), and ast.literal_eval(). Initially, we must ensure that the string contains a valid representation of the dictionary. Let’s discuss how each function will convert the string representation of a dictionary to an original dictionary. Using the eval() function The eval() is a python built-In function that takes a string argument, parses it as a code expression, and evaluates the expression. If the input expression contains a string representation of a dictionary, then the eval() method returns it as a normal Python dictionary. ... Read More

Advertisements