Python Code Samples



Filters


for loop counter in python Django template
kishore_kumar | 5 years, 9 months
{% for my_object in my_object_list %}
    {{ forloop.counter }} {# starting index 1 #}
    {{ forl
python django html
Ramya
Python program to find those numbers which are divisible by 7 and multiple of 5, between 1500 and 2700
Ramya | 5 years, 4 months
mylist = []
for i in range(1500,2700):
	if ((i%7==0) and (i%5==0)):
python
How to connect to presto using python and pyhive
kishore_kumar | 5 years, 8 months
from pyhive import presto
cur = presto.connect('presto.yourhost.com',
                     '8889',
python pyhive presto
How to parse cron string and get next schedule in python
kishore_kumar | 5 years, 1 month
# pip install croniter

from croniter import croniter
python croniter crontab
get month name from datetime in python
kishore_kumar | 2 years, 9 months
from datetime import datetime
today = datetime.today()

python datetime
Get stats ( lines, words, char count ) of file in python
kishore_kumar | 6 years, 4 months
def file_stats(path):
    f = open(path, 'r')
    lines = f.readlines()
python
How to add markers and values to the line plot in python matplotlib
kishore_kumar | 5 years, 11 months
import matplotlib.pyplot as plt

t = ['12-03-18','12-04-18' , '12-05-18', '12-06-18', '12-07-18']
python matplotlib
Ramya
PYTHON: unzip all .gz files in a directory
Ramya | 4 years, 9 months
import os
import gzip
import shutil
python unzip
shuffle two lists and maintain order in python
kishore_kumar | 5 years, 12 months
import random

fruits = ['apples', 'mangoes', 'grapes', 'oranges']
python random
Read nth line in a file using python
kishore_kumar | 5 years
file_ob = open('/path/to/file')
n = 4
for i, line in enumerate(file_ob):
python
Next