Rajendra Dharmkar has Published 568 Articles

How to convert lowercase letters in string to uppercase in Python?

Rajendra Dharmkar

Rajendra Dharmkar

Updated on 19-Oct-2022 09:18:05

You can use the upper() method in Python to convert all lowercase letters in string to uppercase. For example:>>> 'HellO'.upper() HELLO >>> 'leaning tower of pisa'.upper() 'LEANING TOWER OF PISA'

How to remove all trailing whitespace of string in Python?

Rajendra Dharmkar

Rajendra Dharmkar

Updated on 19-Oct-2022 08:57:52

We can use the method rstrip() which returns a copy of the string in which all specified chars have been stripped from the end of the string. The default char to be trimmed is whitespace. For example:>>> '   Hello   '.rstrip() '   Hello' >>> 'Ninja Turtles the movie ... Read More

How to get a list of parameter names inside Python function?

Rajendra Dharmkar

Rajendra Dharmkar

Updated on 18-Oct-2022 11:27:29

To extract the number and names of the arguments from a function or function[something] to return ("arg1", "arg2"), we use the inspect module.The given code is written as follows using inspect module to find the parameters inside the functions a Method and foo.Exampleimport inspect def aMethod(arg1, arg2): pass print(inspect.getargspec(aMethod)) def ... Read More

How does concatenation operator work on tuple in Python?

Rajendra Dharmkar

Rajendra Dharmkar

Updated on 05-Sep-2022 09:17:09

A tuple is a collection of python objects that are separated by commas which are ordered and immutable. Tuples are sequences, just like lists. The differences between tuples and lists are, that tuples cannot be changed unlike lists and tuples use parentheses, whereas lists use square brackets. tup=('tutorials', 'point', 2022, ... 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 − Maths ... 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        File:         OutputThe result of this code is the following form −File: Choose file UploadHere ... 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

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