Rajendra Dharmkar has Published 784 Answers

How do I calculate number of days between two dates using Python?

Rajendra Dharmkar

Rajendra Dharmkar

Updated on 16-May-2022 08:14:21

You can use simple date arithmetic to find the number of days between two dates in Python. Define the 2 dates between which you want to find the difference in days. Then subtract these dates to get a timedelta object and examine the day's property of this object to get ... Read More

How do we use equivalence (“equality”) operator in Python classes?

Rajendra Dharmkar

Rajendra Dharmkar

Updated on 26-Jun-2020 06:37:35

If we use the equality operator as in the code below, we get false as outputclass Integer:     def __init__(self, number):         self.number = number n1 = Integer(1) n2 = Integer(1) print bool(n1 == n2)OutputFalseThis is because Python by default uses the object identifiers for ... Read More

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

Rajendra Dharmkar

Rajendra Dharmkar

Updated on 25-Jun-2020 21:12:50

Passing Drop Down Box Data to CGI ProgramDrop Down Box is used when we have many options available but only one or two will be selected.Here is example HTML code for a form with one drop down box −<form action = "/cgi-bin/dropdown.py" method = "post" target = "_blank"> ... Read More

What is the difference between 'except Exception as e' and 'except Exception, e' in Python?

Rajendra Dharmkar

Rajendra Dharmkar

Updated on 25-Jun-2020 20:57:23

The difference between using ', ' and 'as' in except statements, is as follows:Both ', ' and 'as' are same functionality wise; but their use depends on the python versions as follows.In Python 2.5 and earlier versions, use of the 'comma' is recommended since 'as' isn't supported.In Python 2.6+ versions, ... Read More

How to configure Apache for Python CGI Programming?

Rajendra Dharmkar

Rajendra Dharmkar

Updated on 16-Jun-2020 12:45:17

Configure Apache Web server for CGITo get your server run CGI scripts properly, you have to configure your Web server. We will discuss how to configure your Apache web server to run CGI scripts.Using ScriptAliasYou may set a directory as ScriptAlias Directive (options for configuring Apache). This way, Apache understands ... Read More

How to raise a "File Download" Dialog Box in Python CGI Programming?

Rajendra Dharmkar

Rajendra Dharmkar

Updated on 16-Jun-2020 12:35:07

Sometimes, it is desired that you want to give option where a user can click a link and it will pop up a "File Download" dialogue box to the user instead of displaying actual content. This is very easy and can be achieved through HTTP header. For example, if you want ... Read More

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

Rajendra Dharmkar

Rajendra Dharmkar

Updated on 16-Jun-2020 12:34:27

To upload a file, the HTML form must have the enctype attribute set to multipart/form-data. The input tag with the file type creates a "Browse" button.Example<html> <body>    <form enctype = "multipart/form-data"                      action = "save_file.py" method = "post">    <p>File: ... Read More

How to retrieve cookies in Python CGI Programming?

Rajendra Dharmkar

Rajendra Dharmkar

Updated on 16-Jun-2020 12:32:59

Retrieving CookiesIt is very easy to retrieve all the set cookies. Cookies are stored in CGI environment variable HTTP_COOKIE and they will have following form −key1 = value1;key2 = value2;key3 = value3....Here is an example of how to retrieve cookies.#!/usr/bin/python # Import modules for CGI handling from os import environ ... Read More

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

Rajendra Dharmkar

Rajendra Dharmkar

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

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 ... Read More

What are environment variables available in Python CGI Programming?

Rajendra Dharmkar

Rajendra Dharmkar

Updated on 16-Jun-2020 12:26:28

CGI Environment VariablesAll the CGI programs have access to the following environment variables. These variables play an important role while writing any CGI program.Sr.No.    Variable Name  Description1CONTENT_TYPEThe data type of the content. Used when the client is sending attached content to the server. For example, file upload.2CONTENT_LENGTHThe length of ... Read More

1 2 3 4 5 6 7 ... 79 Next
Advertisements