Python Code Samples


Get stats ( lines, words, char count ) of file in python
kishore_kumar | 1 year, 5 months
def file_stats(path):
    f = open(path, 'r')
    lines = f.readlines()
for loop counter in python Django template
kishore_kumar | 10 months
{% for my_object in my_object_list %}
    {{ forloop.counter }} {# starting index 1 #}
    {{ forl
python django html
shuffle two lists and maintain order in python
kishore_kumar | 1 year
import random

fruits = ['apples', 'mangoes', 'grapes', 'oranges']
python random
How to add markers and values to the line plot in python matplotlib
kishore_kumar | 1 year
import matplotlib.pyplot as plt

t = ['12-03-18','12-04-18' , '12-05-18', '12-06-18', '12-07-18']
python matplotlib
How to connect to presto using python and pyhive
kishore_kumar | 9 months, 2 weeks
from pyhive import presto
cur = presto.connect('',
python pyhive presto
List all files and folders using python os module
kishore_kumar | 1 year, 5 months
import os

def list_files_folders(path):
python python-os
use python requests to get contents of url ( get request )
kishore_kumar | 1 year, 2 months
import requests

req = requests.get("")
python python-requests
Get os details using python os
kishore_kumar | 1 year, 5 months
import os
print os.uname()
# Don't use os.system('uname -a'), its just executing "uname -a" comman
python python-os
generate random numbers matrix with numpy python
kishore_kumar | 1 year, 2 months
import numpy as np

random_arr = np.random.randint(1,50,9)
python numpy
Shell Script to Generate the SSH key and display it on output screen also create virtualenv
sandeep | 1 year, 5 months
export PATH=$WORKSPACE/resources/chromedriver/mac:$WORKSPACE/venv/bin:/usr/local/bin:$PATH
export P
shell auto ssh key