- 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
Rajendra Dharmkar has Published 452 Articles
Rajendra Dharmkar
628 Views
You can use the tempfile module to create a unique temporary file in the most secure manner possible. There are no race conditions in the file’s creation. The file is readable and writable only by the creating user ID. Note that the user of mkstemp() is responsible for deleting the ... Read More
Rajendra Dharmkar
888 Views
The shutil module provides functions for copying files, as well as entire folders.Calling shutil.copy(source, destination) will copy the file at the path source to the folder at the path destination. (Both source and destination are strings.) If destination is a filename, it will be used as the new name of ... Read More
Rajendra Dharmkar
921 Views
As of writing this, Python support for Azure Functions is experimental. So right now there is no way to directly get a module from a package manager to be installed on your instance. You'll need to bring your own modules with code. No modules are available by default on Azure ... Read More
Rajendra Dharmkar
380 Views
To convert byte literals to Python strings, you need to decode the bytes. It can be done using the decode method on the bytes object. example>>> b"abcde".decode("utf-8") u'abcde'You can also map bytes to chr if the bytes represent ASCII encoding as follows −bytes = [112, 52, 52] print("".join(map(chr, bytes)))Outputp44Read More
Rajendra Dharmkar
152 Views
In the following code, we import sqlite3 module and establish a database connection. We create a table and then insert data and retrieve information from the sqlite3 database and close the connection finally.Example#sqlitedemo.py import sqlite3 from employee import employee conn = sqlite3.connect('employee.db') c=conn.cursor() c.execute(‘’’CREATE TABLE employee(first text, last text, pay ... Read More
Rajendra Dharmkar
8K+ Views
We have this code below which will the given json object as a parameter to a python function.exampleimport json json_string = '{"name":"Rupert", "age": 25, "desig":"developer"}' print type (json_string) def func(strng): a =json.loads(strng) print type(a) for k, v in a.iteritems(): ... Read More
Rajendra Dharmkar
1K+ Views
We return a json object from a python function as follows using given python dictionary.Exampleimport json a = {'name':'Sarah', 'age': 24, 'isEmployed': True } # a python dictionary def retjson(): python2json = json.dumps(a) print python2json retjson()Output{"age": 24, "isEmployed": true, "name": "Sarah"}
Rajendra Dharmkar
1K+ Views
If we define except clause with no exceptions, it can handle all types of exceptions. However, neither it’s a good coding practice nor it is recommended.Exampletry: print 'foo'+'qux'+ 7 except: print' There is error'OutputYou get the outputThere is errorThis type of Python try-except block can handle all types of exceptions, ... Read More
Rajendra Dharmkar
889 Views
The common method to handle exceptions in python is using the "try-except" block. We can even include an else clause after except clause. The statements in the else block are executed if there is no exception in the try statement.The optional else clause is executed if and when control flows ... Read More
Rajendra Dharmkar
165 Views
We use the most specific exception constructor that fits our specific issue rather than raise generic exceptions. To catch our specific exception, we'll have to catch all other more specific exceptions that subclass it.We should raise specific exceptions and handle the same specific exceptions.To raise the specific exceptions we use ... Read More