Python Code Samples



Filters


for loop counter in python Django template
kishore_kumar | 5 years, 2 months
{% for my_object in my_object_list %}
    {{ forloop.counter }} {# starting index 1 #}
    {{ forl
python django html
How to get first element of the list in Django template
kishore_kumar | 5 years, 5 months
<h3> Print all elements</h3>
<div>
    {% for item in my_list %}
html python django
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, 1 month
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, 6 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, 9 months
def file_stats(path):
    f = open(path, 'r')
    lines = f.readlines()
python
get month name from datetime in python
kishore_kumar | 2 years, 2 months
from datetime import datetime
today = datetime.today()

python datetime
Ramya
PYTHON: unzip all .gz files in a directory
Ramya | 4 years, 2 months
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, 4 months
import matplotlib.pyplot as plt

t = ['12-03-18','12-04-18' , '12-05-18', '12-06-18', '12-07-18']
python matplotlib
get sublist or sub matrix of numpy arrays
kishore_kumar | 5 years, 6 months
import numpy as np
random_arr = np.random.randint(1,50,9)
mat1 = ran.reshape(3,3)
python numpy
Next