- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 10784 Articles for Python
229 Views
Radio Buttons are used when only one option is required to be selected.ExampleHere is example HTML code for a form with two radio buttons − Maths Physics The result of this code is the following form −Below is radiobutton.py script to handle input given by web browser for radio button −#!/usr/bin/python # Import modules for CGI handling import cgi, cgitb # Create instance of FieldStorage form = cgi.FieldStorage() # Get data from fields if form.getvalue('subject'): subject = form.getvalue('subject') else: subject = "Not set" print "Content-type:text/html\r\r" print "" print "" print "Radio - Fourth CGI Program" ... Read More
411 Views
Checkboxes are used when more than one option is required to be selected.ExampleHere is example HTML code for a form with two checkboxes − Maths Physics OutputThe result of this code is the following form −Below is checkbox.cgi script to handle input given by web browser for checkbox button.#!/usr/bin/python # Import modules for CGI handling import cgi, cgitb # Create instance of FieldStorage form = cgi.FieldStorage() # Get data from fields if form.getvalue('maths'): math_flag = "ON" else: math_flag = "OFF" if form.getvalue('physics'): physics_flag = "ON" else: physics_flag = "OFF" print "Content-type:text/html\r\r" print "" ... Read More
474 Views
A generally more reliable method of passing information to a CGI program is the POST method. This packages the information in exactly the same way as GET methods, but instead of sending it as a text string after a ? in the URL it sends it as a separate message. This message comes into the CGI script in the form of the standard input.ExampleBelow is same hello_get.py script which handles GET as well as POST method.#!/usr/bin/python Import modules for CGI handling import cgi, cgitb # Create instance of FieldStorage form = cgi.FieldStorage() # Get data from fields first_name = form.getvalue('first_name') ... Read More
2K+ Views
The 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 string that appears in your browser's Location:box. Never use GET method if you have password or other sensitive information to pass to the server.The GET method has size limitation: only 1024 characters can be sent in a request string. The GET method sends information using QUERY_STRING header and will be accessible in your ... Read More
2K+ Views
All 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 the query information. It is available only for POST requests.3HTTP_COOKIEReturns the set cookies in the form of key & value pair.4HTTP_USER_AGENTThe User-Agent request-header field contains information about the user agent originating the request. It is name of the web browser.5PATH_INFOThe path for the CGI script.6QUERY_STRINGThe URL-encoded information that is sent with GET method ... Read More
234 Views
Literal charactersSr.No.Example & Description1pythonMatches beginning of line.Character classesSr.No.Example & Description1[Pp]ythonMatch "Python" or "python"2rub[ye]Match "ruby" or "rube"3[aeiou]Match any one lowercase vowel4[0-9]Match any digit; same as [0123456789]5[a-z]Match any lowercase ASCII letter6[A-Z]Match any uppercase ASCII letter7[a-zA-Z0-9]Match any of the above8[^aeiou]Match anything other than a lowercase vowel9[^0-9]Match anything other than a digitSpecial Character ClassesSr.No.Example & Description1.Match any character except newline2\dMatch a digit: [0-9]3\DMatch a nondigit: [^0-9]4\sMatch a whitespace character: [ \t\r\f]5\SMatch nonwhitespace: [^ \t\r\f]6\wMatch a single word character: [A-Za-z0-9_]7\WMatch a nonword character: [^A-Za-z0-9_]Repetition CasesSr.No.Example & Description1ruby?Match "rub" or "ruby": the y is optional2ruby*Match "rub" plus 0 or more ys3ruby+Match "rub" plus 1 or more ... Read More
1K+ Views
Suppose we have a non-negative integer number num. For each number i in the range 0 ≤ i ≤ num we have to calculate the number of 1's in their binary counterpart and return them as a list. So if the number is 5, then the numbers are [0, 1, 2, 3, 4, 5], and number of 1s in these numbers are [0, 1, 1, 2, 1, 2]To solve this, we will follow these steps −res := an array which holds num + 1 number of 0soffset := 0for i in range 1 to num + 1if i and i ... Read More
478 Views
Suppose there is a list of non-negative integers, we have to arrange them such that they form the largest number. So if the array is [10, 2], then the largest number will be 210.To solve this, we will follow these steps −Arrange the numbers where the most significant digits are greater than place them at first, like this arrangement the numbers. After that just join the numbers from the array.ExampleLet us see the following implementation to get a better understanding − Live Demofrom functools import cmp_to_key class Solution(object): def largestNumber(self, nums): for i in range(len(nums)): ... Read More
784 Views
Suppose we have one non-empty string s and a dictionary wordDict. That is containing a list of non-empty words, determine when s can be segmented into a space-separated sequence of one or more dictionary words. We have to follow some rules −The same word in the dictionary may be reused multiple numbers of times in the segmentation.We can assume that the dictionary does not contain duplicate words.Suppose the string s = “applepenapple”, and word dictionary is like [“apple”, “pen”], then the output will be true because the string s can be segmented as “apple pen apple”.Let us see the steps ... Read More