Python Code Samples



Filters


Ramya
PYTHON: unzip all .gz files in a directory
Ramya | 1 year, 1 month
import os
import gzip
import shutil
python unzip
Ramya
Python: Vending Machine
Ramya | 1 year, 8 months
class SodaMachine:
    def __init__(self,product,price):
        self.product=product
python >>>from <file_name> import <class_name> >>>shop=class_name("product",price) #Instantiate
python
generate random numbers matrix with numpy python
kishore_kumar | 2 years, 6 months
import numpy as np

random_arr = np.random.randint(1,50,9)
python numpy
Matplotlib pie chart replace auto labelled values with original values
kishore_kumar | 2 years, 4 months
import matplotlib.pyplot as plt

labels = 'Grapes', 'Oranges', 'Mangoes', 'Apples'
*autopct*: [ *None* | format string | format function ] If not *None*, is a string or function
python matplotlib
Example to use a DAG to run a jar file.
Reshma | 1 year, 6 months
from airflow import DAG
from airflow.operators import BashOperator
from datetime import datetime
python airflow jar
List all files and folders using python os module
kishore_kumar | 2 years, 9 months
import os

def list_files_folders(path):
python python-os
convert and decode base64 string into pdf using python
kishore_kumar | 1 year, 7 months
import base64

b64str = "a29kZXJwbGFjZQ=="
python base64
use python requests to get contents of url ( get request )
kishore_kumar | 2 years, 6 months
import requests

req = requests.get("https://httpbin.org/get")
python python-requests
Matrix transpose using list comprehensions in python
harika | 2 years, 1 month
a = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
#Procedure1:--------
transposed = [[row[i] for row in a ] fo
List comprehensions in python basically reduce the loc. Check the difference between two procudures
python matrix list
delete files older than n days in a directory using python
kishore_kumar | 1 year, 3 months
import os
import time
base_path = '/home/kishore/my_files'
python os
Prev Next