Python Code Samples



Filters


Save full traceback from exception in python
kishore_kumar | 5 years, 2 months
import traceback

l = [1,2,3]
python exception
durga
Writing into files in python
durga | 5 years, 3 months
file = open('open.txt','w') 
 
file.write('Hi there!') 
python file handling
Ramya
Indexed DataFrame using list of dictionaries
Ramya | 5 years, 3 months
import pandas as pd
data = [{'Python': 90, 'C': 84,'java':65},{'Python': 78, 'C': 90, 'java': 65}]
python pandas dataframe
How to get first day of the month in python
kishore_kumar | 2 years, 10 months
from datetime import datetime

first_day = datetime.today().date().replace(day=1)
python datetime
Remove directory / folder in python
harika | 5 years, 9 months
'''
You can remove empty directory by rmdir function.
But to remove non empty directory we have to
Shuttle : A module that offers a number of high-level operations on files and collections of files.
shutil python os
get all keys from redis with python
kishore_kumar | 4 years, 11 months
import redis # pip install redis
r = redis.Redis(host='localhost', port='6379')

python redis
How to load a pickle file in python
harika | 5 years, 1 month
with open('train.pickle', 'rb') as f:
    X_train, y_train = pickle.load(f)
python pickle file
send mail using sendgrid python
kishore_kumar | 5 years, 4 months
import os
from sendgrid import SendGridAPIClient
from sendgrid.helpers.mail import Mail
python sendgrid
convert python date time object to specific format using strftime
kishore_kumar | 5 years, 3 months
import datetime

st = "2019-08-19 05:40"
python datetime
Python pickle dump
Reshma | 4 years, 11 months
import pickle

number_of_data = int(input('Enter the number of data : '))
python pickle dump
Prev Next