Working with docx Module in Python

Nizamuddin Siddiqui
Updated on 08-Aug-2020 08:16:34

9K+ Views

Word documents contain formatted text wrapped within three object levels. Lowest level- Run objects, Middle level- Paragraph objects and Highest level- Document object.So, we cannot work with these documents using normal text editors. But we can manipulate these word documents in python using the python-docx module.The first step is to install this third-party module python-docx. You can use pip “pip install python-docx”After installation import “docx” NOT “python-docx”.Use “docx.Document” class to start working with the word document.Example# import docx NOT python-docx import docx # create an instance of a word document doc = docx.Document() # add a heading of level 0 ... Read More

Word Embedding Using Word2Vec in Python

Nizamuddin Siddiqui
Updated on 08-Aug-2020 08:15:04

585 Views

Word Embedding is a language modeling technique used for mapping words to vectors of real numbers. It represents words or phrases in vector space with several dimensions. Word embeddings can be generated using various methods like neural networks, co-occurrence matrix, probabilistic models, etc.Word2Vec consists of models for generating word embedding. These models are shallow two-layer neural networks having one input layer, one hidden layer and one output layer.Example# importing all necessary modules from nltk.tokenize import sent_tokenize, word_tokenize import warnings warnings.filterwarnings(action = 'ignore') import gensim from gensim.models import Word2Vec   #  Reads ‘alice.txt’ file sample = open("C:\Users\Vishesh\Desktop\alice.txt", "r") s = sample.read()   # ... Read More

Window Size Adjustment in Kivy

Nizamuddin Siddiqui
Updated on 08-Aug-2020 08:13:23

743 Views

Kivy is a platform independent GUI tool in Python. As it can be run on Android, IOS, linux and Windows etc. Kivy provides you the functionality to write the code for once and run it on different platforms. It is basically used to develop the Android application, but it does not mean that it can not be used on Desktops applications.Kivy is that platform where the size does not matter a lot as it is self-adjusting accordingly but What if we want to fix the size to some extent whether its hight wise or width wise or free from boundation depends ... Read More

Which is Faster to Initialize Lists in Python

Nizamuddin Siddiqui
Updated on 08-Aug-2020 08:11:16

205 Views

Python is a very flexible language where a single task can be performed in a number of ways, for example initializing lists can be performed in many ways. However, there are subtle differences in these seemingly similar methods. Python which is popular for its simplicity and readability is equally infamous for being slow compared to C++ or Java. The ‘for’ loop is especially known to be slow whereas methods like map() and filter() known to be faster because they are written in C.Example Live Demo# import time module to calculate times import time # initialise lists to save the times forLoopTime ... Read More

Uninstall Software Using Package Management in PowerShell

Chirag Nagrekar
Updated on 08-Aug-2020 07:45:00

3K+ Views

There are mainly 3 methods by which you can uninstall software using PowerShell.WMI Method.Using Package providerUninstallation String.Here, we will discuss the method to uninstall software using Package management.You can uninstall the software or packages which are installed with the package providers. You can get the list of the package providers using Get-PackageProvider command.PS C:\Users\Administrator> Get-PackageProvider | Select Name, Version Name          Version ----          ------- msi           3.0.0.0 msu           3.0.0.0 PowerShellGet 1.0.0.1 Programs      3.0.0.0So the packages which are installed with msi, msu, Programs ... Read More

Uninstall Software Using WMI in PowerShell

Chirag Nagrekar
Updated on 08-Aug-2020 07:42:21

2K+ Views

There are mainly 3 methods by which you can uninstall software using PowerShell.WMI Method.Using Package providerUninstallation String.We will discuss here the WMI method to uninstall software.WMI methodWith WMI class Win32_Product you can retrieve the list of software uninstalled in your local or the remote systems. If you need specific software, you can filter by its name. For example, Get-WmiObject Win32_Product -Filter "Name='Vmware tools'"Or You can retrieve the name of the installed software using the Where-Object pipeline command.Get-WmiObject Win32_Product | Where{$_.Name -eq "Vmware tools"}OutputPS C:\Users\Administrator> Get-WmiObject Win32_Product | Where{$_.Name -eq "Vmware tools"} IdentifyingNumber : {D533345C-7F8D-4807-AE80-E06CE2045B0E} Name           ... Read More

Explain PowerShell Profile

Chirag Nagrekar
Updated on 08-Aug-2020 07:39:52

566 Views

When you open PowerShell, it loads the profile just like the Windows operating system. When you log in to windows OS you are logged into your profile and every user has their individual profile. It is called the current profile for the current host.To check your profile, type $Profile command in the PowerShell console.PS C:\Users\Administrator> $profile C:\Users\Administrator\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.p s1This was for Powershell console but let's check if Powershell uses the same profile for ISE.PS C:\> $profile C:\Users\Administrator\Documents\WindowsPowerShell\Microsoft.PowerShellISE_profil e.ps1So the ISE has its own profile too and both are stored in the $Home directory. What if we use the $profile for VSCode.PS ... Read More

Ways to Merge Strings into List in Python

Nizamuddin Siddiqui
Updated on 06-Aug-2020 14:27:21

232 Views

While developing an application, there come many scenarios when we need to operate on the string and convert it as some mutable data structure, say list.Example# Importing ast library import ast # Initialization of strings str1 ="'Python', 'for', 'fun'" str2 ="'vishesh', 'ved'" str3 ="'Programmer'" # Initialization of list list = [] # Extending into single list for x in (str1, str2, str3):    list.extend(ast.literal_eval(x)) # printing output print(list) # using eval # Initialization of strings str1 ="['python, 'for', ''fun']" str2 ="['vishesh', 'ved']" str3 ="['programmer']" out = [str1, str2, str3] out = eval('+'.join(out)) # printing output print(out)

Ways to Iterate Tuple List of Lists in Python

Nizamuddin Siddiqui
Updated on 06-Aug-2020 14:25:29

184 Views

List is an important container and used almost in every code of day-day programming as well as web-development, more it is used, more is the requirement to master it and hence knowledge of its operations is necessary.Example# using itertools.ziplongest # import library from itertools import zip_longest   # initialising listoflist test_list = [    [('11'), ('12'), ('13')],    [('21'), ('22'), ('23')],    [('31'), ('32'), ('33')]    ] # printing intial list print ("Initial List = ", test_list)   # iterate list tuples list of list into single list res_list = [item for my_list in zip_longest(*test_list) for item in my_list if ... Read More

Ways to Invert Mapping of Dictionary in Python

Nizamuddin Siddiqui
Updated on 06-Aug-2020 14:22:50

358 Views

Dictionary is a collection which is unordered, changeable and indexed. In Python, dictionaries are written with curly brackets, and they have keys and values. It is widely used in day to day programming, web development, and machine learning.Example Live Demo# using dict comprehension # initialising dictionary ini_dict = {101: "vishesh", 201 : "laptop"} # print initial dictionary print("initial dictionary : ", str(ini_dict)) # inverse mapping using dict comprehension inv_dict = {v: k for k, v in ini_dict.items()} # print final dictionary print("inverse mapped dictionary : ", str(inv_dict)) # using zip and dict functions # initialising dictionary ini_dict = {101: "vishesh", 201 ... Read More

Advertisements