Python Code Samples



Filters


Get stats ( lines, words, char count ) of file in python
kishore_kumar | 1 year, 3 months
def file_stats(path):
    f = open(path, 'r')
    lines = f.readlines()
python
for loop counter in python Django template
kishore_kumar | 8 months, 1 week
{% 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 | 10 months, 4 weeks
import random

fruits = ['apples', 'mangoes', 'grapes', 'oranges']
python random
How to add markers and values to the line plot in python matplotlib
kishore_kumar | 10 months, 2 weeks
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 | 7 months, 3 weeks
from pyhive import presto
cur = presto.connect('presto.yourhost.com',
                     '8889',
python pyhive presto
List all files and folders using python os module
kishore_kumar | 1 year, 3 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, 1 month
import requests

req = requests.get("https://httpbin.org/get")
python python-requests
Get os details using python os
kishore_kumar | 1 year, 3 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
import numpy as np

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