Rajendra Dharmkar has Published 189 Articles

How to replace \\ with in Python?

Rajendra Dharmkar

Rajendra Dharmkar

Updated on 30-Sep-2019 08:23:04

869 Views

There are two ways to go about replacing \ with \ or unescaping backslash escaped strings in Python. First is using literal_eval to evaluate the string. Note that in this method you need to surround the string in another layer of quotes. For example:>>> import ast >>> a = '"Hello, ... Read More

How do you properly ignore Exceptions in Python?

Rajendra Dharmkar

Rajendra Dharmkar

Updated on 27-Sep-2019 07:10:07

582 Views

This can be done by following codestry: x, y =7, 0 z = x/y except: passORtry: x, y =7, 0 z = x/y except Exception: passThese codes bypass the exception in the try statement and ignore the except clause and don’t raise any exception.The difference in the above codes is ... Read More

How to setup cookies in Python CGI Programming?

Rajendra Dharmkar

Rajendra Dharmkar

Updated on 30-Aug-2019 06:06:48

819 Views

Setting up CookiesIt is very easy to send cookies to browser. These cookies are sent along with HTTP Header before to Content-type field. Assuming you want to set UserID and Password as cookies. Setting the cookies is done as follows −#!/usr/bin/python print "Set-Cookie:UserID = XYZ;\r" print "Set-Cookie:Password = XYZ123;\r" print ... Read More

How many Python classes should I put in one file?

Rajendra Dharmkar

Rajendra Dharmkar

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

3K+ Views

Python code is organized in files called "modules" and groups of related modules called “packages".A module is a distinct unit that may have one or more closely-related classes. Modules need to be imported before they are read, used, maintained and extended if needed. So a module is a unit or ... Read More

Is there any tool that can convert an XSD file to a Python class as JAXB does for Java?

Rajendra Dharmkar

Rajendra Dharmkar

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

1K+ Views

I would recommend generateDS for converting a XSD file to a Python class . In my opinion, it is a good tool for the said purpose.It (generatS) generates the Python class with all methods (setters and getters, export to XML, import from XML). It does a good job and works ... Read More

How do you compare Python objects with .NET objects?

Rajendra Dharmkar

Rajendra Dharmkar

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

196 Views

By default, all .NET objects are reference types and their equality and hash code is determined by their memory address. Additionally, assigning a variable to an existing object just makes it point to that address in memory, so there is no costly copying occurring. It appears that this is true ... Read More

How to compress Python objects before saving to cache?

Rajendra Dharmkar

Rajendra Dharmkar

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

409 Views

We need sometimes to compress Python objects (list, dictionary, string, etc) before saving them to cache and decompress after reading from cache.Firstly we need to be sure we need to compress the objects. We should check if  the data structures/objects are too big just to fit uncompressed in the cache. ... Read More

What are repeating character classes used in Python regular expression?

Rajendra Dharmkar

Rajendra Dharmkar

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

550 Views

A character class followed by operators like '?', '*' or '+' are called repeating character classes.If you repeat a character class by using the '?', '*' or '+' operators, you will repeat the entire character class, and not just the character that it matched. The regex '[0-9]+' can match '579' ... Read More

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

Rajendra Dharmkar

Rajendra Dharmkar

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

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

How do cookies work in Python CGI Programming?

Rajendra Dharmkar

Rajendra Dharmkar

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

578 Views

Using Cookies in CGIHTTP protocol is a stateless protocol. For a commercial website, it is required to maintain session information among different pages. For example, one user registration ends after completing many pages. How to maintain user's session information across all the web pages?In many situations, using cookies is the ... Read More

Advertisements