What is Pickling in Python?

Python pickle module is used for serializing and de-serializing a Python object structure.

Pickling” is the process whereby a Python object is converted into a byte stream,

and “unpickling” is the inverse operation, whereby a byte stream is converted back into an object


import pickle

def storeData():

  db = {}
  db['vishavjeet'] = {'key': 'Vishavjeet', 'name': 'Vishavjeet Singh', 'age': 28, 'pay': 40000}
  db['Scarpion'] = {'key': 'Scarpion', 'name': 'Scarpion', 'age': 28, 'pay': 50000}
  # Its important to use binary mode
  with open('my_pickle_file', 'ab') as f:
    pickle.dump(db, f) # source, destination

def loadData():
  # for reading also binary mode is important
  with open('my_pickle_file', 'rb') as f:
    db = pickle.load(f)

  for keys in db:
    print(keys, '=>', db[keys])

storeData() # pickling
loadData() # unpickling
View More...

Vim Command

1. Insert mode (Where you can just type like normal text editor. Press i for insert mode)

2. Command mode (Where you give commands to the editor to get things done . Press ESC for command mode)

Most of them below are in command mode

x - to delete the unwanted character

u - to undo the last the command and U to undo the whole line

CTRL-R to redo

A - to append text at the end

:wq - to save and exit

:q! - to trash all changes

dw - move the cursor to the beginning of the word to delete that word

2w - to move the cursor two words forward.

3e - to move the cursor to the end of the third word forward.

0 (zero) to move to the start of the line.

d2w - which deletes 2 words .. number can be changed for deleting the number of consecutive words like d3w

dd to delete the line and 2dd to delete to line .number can be changed for deleting the number of consecutive words

View More...

Deployment On DigitalOcean for Python Flask project

>sudo apt install libapache2-mod-wsgi-py3

www>mkdir flaskapp

>cd flaskapp

>mkdir flaskapp

>sudo apt install python3-pip

>pip3 install virtualenv

>sudo virtualenv venv

>source venv/bin/activate

>pip3 install flask request pandas flask-slqalchemy

>cd /etc/apache2/sites-available

>cp 000-default.conf flaskapp.conf

>nano flaskapp.conf

Open flaskapp.conf and copy paste below code:

<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.python-ds.com
ServerName python-ds.com
ServerAlias www.python-ds.com
ServerAdmin python.ds.com@gmail.com
WSGIScriptAlias / /var/www/flaskapp/flaskapp.wsgi
<Directory /var/www/flaskapp/flaskapp/>
Order allow,deny
Allow from all
Alias /static /var/www/flaskapp/flaskapp/static
<Directory /var/www/flaskapp/static/>
Order allow,deny
Allow from all
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

>sudo a2ensite flaskapp.conf

>service apache2 restart

>cd /var/www/flaskapp

>sudo nano flaskapp.wsgi

open flaskapp.wsgi and copy paste below code according to your need:

import sys
import logging
from flaskapp import app as application
application.secret_key = '\xfd{H\xe5<\x95\xf9\xe3\x96.5\xd1\x01O<!\xd5\xa2\xa0\x9fR"\xa1\xa8'

>python3 __init__.py

>service apache2 restart

View More...

Deployment On DigitalOcean for php/html project

Step1: SSH Login for server access

$> ssh root@168.0.x.x.0

>cd home

>cd /

>adduser vishavjeet

>usermod -aG sudo vishavjeet

>ufw app list

>ufw status

>ufw allow OpenSSH

>ufw enable

>ufw status


#login as vishavjeet

> sudo apt update

>sudo apt install apache2

>sudo ufw app list

>sudo ufw app info "Apache Full"

>sudo ufw allow in "Apache Full"

>sudo apt install mysql-server

>sudo mysql

>select user, authentication_strings, plugin, host from myqsl.user;


>sudo mysql -p


>sudo apt install php libapache2-mod-php php-mysql

#how can open default index.php

>nano /ect/apache2/mods-enables/dir.conf

<ifModule mod.dir>

Dir index.php index.cgi, ..index.html


>sudo service apache2 restart

>sudo apt install phpmyadmin php-mbstring php-gettext

>sudo phpenmod mbstring

>sudo service apache2 restart

>sudo mysql -p

>mysq>grant all privilleges en *.* 'vishavjeet'@'localhost' with grant option;

www>mkdir project_first

>ls -lart

>sudo chown -R $USER:$USER project_first

>ls -lart

project_first>nano index.html

>cd /etc/apache2/sites-available/

>cp 000-default.conf project_first.conf


000-default.conf project_first.conf

>sudo nano project_first.conf

<VirtualHost *:80>

ServevAdmin vishavjeet@tech-overflow.com

ServerName tech-overflow.com

ServerAlias www.tech-overflow.com

DocumentRoot /var/www/project_first


>sudo a2ensite project_first.conf

>sudo a2dissite 000-default.conf

>sudo service apache2 restart

>sudo apache2ctl config test

Step2:  Domain configuration in Goddady

A @ 600sec

Cname www @ h hours

View More...

How to make generator to produce N prime number?

def is_prime(num):

    for n in range(2, num):

        if num % n == 0:

            return False

    return True

# using Generator(Yield)

def generate_n_prime(num):

    i = 2

    while num:

        if is_prime(i):

           yield i

         num -= 1

      i += 1

it = generate_n_prime(10)

for i in it:

    print(i, end=' ')

#2 3 5 7 11 13 17 19 23 29

View More...

First Previous 9 10 11 12 13 Next Last