
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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 33676 Articles for Programming

13K+ Views
A module can find out its own module name by looking at the predefined global variable __name__. If this has the value '__main__', the program is running as a script. Example def main(): print('Testing…...') ... if __name__ == '__main__': main() Output Testing…... Modules that are usually used by importing them also provide a command-line interface or a selftest, and only execute this code after checking __name__. The__name__ is an in-built variable in python language, we can write a program just to see the value of this variable. Here’s an ... Read More

181 Views
To parcel out work among a bunch of worker threads, use the concurrent.futures module, especially the ThreadPoolExecutor class. With that an alternative, if you want fine control over the dispatching algorithm, you can write your own logic manually. Use the queue module to create a queue containing a list of jobs. The Queue class maintains a list of objects and has a .put(obj) method that adds items to the queue and a .get() method to return them. The class will take care of the locking necessary to ensure that each job is handed out exactly once. Example Following is an ... Read More

976 Views
To implement persistent objects in Python, use the following libraries. shelve pickle The shelve module A “shelf” is a persistent, dictionary-like object. The difference with “dbm” databases is that the values (not the keys!) in a shelf can be essentially arbitrary Python objects — anything that the pickle module can handle. This includes most class instances, recursive data types, and objects containing lots of shared sub-objects. It is having some key methods − shelve.open() − Open a persistent dictionary. The filename specified is the base filename for the underlying database. As a side-effect, an extension may be ... Read More

777 Views
To create documentation from doc strings, we can use the following packages and modules − Pydoc Epydoc Sphinx Let us understand them one by one − Pydoc The pydoc module can create HTML from the doc strings in your Python source code. The pydoc module automatically generates documentation from Python modules. The documentation can be presented as pages of text on the console, served to a web browser, or saved to HTML files. For modules, classes, functions and methods, the displayed documentation is derived from the docstring (i.e. the __doc__ attribute) of the object, and recursively of its ... Read More

6K+ Views
To complete remove Python from the Windows machine, uninstall it, remove the path and the remaining files if still present on the system. Uninstall Python To uninstall Python, go to START, type Python. Click Uninstall − After clicking Uninstall, the following screen is visible. To uninstall Python, you need to uninstall these two − Right-click each one by one and press Uninstall − It is uninstalling − Python uninstalled successfully Remove Files Even after uninstalling Python, sometimes the installation files remain in the system itself. Do not worry about them. Reach the folder wherein we ... Read More

620 Views
The Global Interpretor Lock is a mutex in Python. Let’s first understand what is a Global Interpreter Lock (GIL) − What is a GIL? The global interpreter lock, or GIL, is a mutex that − Protects access to Python objects, Prevents multiple threads from executing Python bytecodes at once. Prevents race conditions. Ensures thread safety. The Python interpreter is not fully thread-safe. In order to support multi-threaded Python programs, there’s a global lock, called the global interpreter lock or GIL. Without the lock, even the simplest operations could cause problems in a multi-threaded program: for example, when two ... Read More

217 Views
With Python, we can also create Web Applications. Python provides multiple frameworks for the web development. Let us see some them which are widely used. Django Django is a high-level Python web framework that encourages rapid development and clean, pragmatic design. Built by experienced developers, it takes care of much of the hassle of web development, so you can focus on writing your app without needing to reinvent the wheel. Django is an MVT web framework that is used to build web applications. The huge Django webframework comes with so many batteries included that developers often get amazed as to ... Read More

14K+ Views
To create a .pyc file in Python, use the PyCompile. The official documentation even suggests the same as shown below − The py_compile module The py_compile module provides a function to generate a byte-code file from a source file, and another function used when the module source file is invoked as a script. The py_compile.compile() compile a source file to byte-code and write out the byte-code cache file. Now, let us see the example import py_compile py_compile.compile("demo.py") Use the py_compile.main() import py_compile py_compile.main(['File1.py', 'File2.py', 'File3.py']) The compileall module The compileall module provides some utility functions to support ... Read More

932 Views
To make an executable from a Python script, you need to install the PyInstaller library. Install the PyInstaller Library To install the PyInstaller library, use the pip in Python. Type the below command on Command Prompt and press Enter − pip install pyinstaller Our Python Script Let’s say we have the following Python Script, wherein we have displayed checkbox using Tkinter. Our file Demo.py is saved on the Desktop with the path − C:\Users\hp\Desktop\Demo.py Example Here’s the code of Demo.py. import tkinter from tkinter import * top = tkinter.Tk() CheckVar1 = IntVar() CheckVar2 = IntVar() C1 = ... Read More

4K+ Views
The coding standards i.e., the style guide for Python are provided by a document called PEP8. The PEP8 is Python Enhancement Proposal 8. It is a document that provides coding conventions for the Python code. Here’s the style guide − Naming Conventions The following are the currently recommended naming standard. Avoid These Names Never use the characters ‘l’ (lowercase letter el), ‘O’ (uppercase letter oh), or ‘I’ (uppercase letter eye) as single character variable names. Package and Module Names Modules should have short, all-lowercase names. Underscores can be used in the module name if it improves readability. Python packages should ... Read More