Python Code Samples



Filters


for loop counter in python Django template
kishore_kumar | 5 years, 1 month
{% 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 | 4 years, 8 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
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 | 4 years, 5 months
# pip install croniter

from croniter import croniter
python croniter crontab
Get stats ( lines, words, char count ) of file in python
kishore_kumar | 5 years, 8 months
def file_stats(path):
    f = open(path, 'r')
    lines = f.readlines()
python
get month name from datetime in python
kishore_kumar | 2 years, 1 month
from datetime import datetime
today = datetime.today()

python datetime
Ramya
PYTHON: unzip all .gz files in a directory
Ramya | 4 years, 1 month
import os
import gzip
import shutil
python unzip
How to add markers and values to the line plot in python matplotlib
kishore_kumar | 5 years, 3 months
import matplotlib.pyplot as plt

t = ['12-03-18','12-04-18' , '12-05-18', '12-06-18', '12-07-18']
python matplotlib
shuffle two lists and maintain order in python
kishore_kumar | 5 years, 3 months
import random

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