Try-Catch-Custom-Error

Sat 17 May 2025

title: "Try Catch with Custom Error" author: "Rj" date: 2019-04-20 description: "List Test" type: technical_note draft: false


class NegativeMarksError(Exception):
   pass
def check_marks(mark):
    try:

        if(mark < 0):
            raise NegativeMarksError

        if(mark > 50):
            print('pass')
        else:
            print('fail')
    except ValueError:
        print('ValueError: Some value error')
    except TypeError:
        print('TypeError: Cannot …

Category: basics

Read More

Try-Catch-Raise-Error

Sat 17 May 2025

title: "Try Catch with Raise Error" author: "Rj" date: 2019-04-20 description: "List Test" type: technical_note draft: false


def check_marks(mark):
    try:

        if(mark < 0):
            raise ValueError

        if(mark > 50):
            print('pass')
        else:
            print('fail')
    except ValueError:
        print('ValueError: Some value error')
    except TypeError:
        print('TypeError: Cannot convert into int')
check_marks …

Category: basics

Read More

Ttl-Cache

Sat 17 May 2025

title: "TTL Cache" author: "Rj" date: 2019-04-20 description: "-" type: technical_note draft: false


from cachetools import TTLCache
cache = TTLCache(maxsize=10, ttl=10)
cache['city'] = 'Toronto'
cache['city']
'Toronto'
# Run the cell below after 10 seconds
cache['city']
'Toronto'
# more 
# https://stackoverflow.com/questions/31771286/python-in-memory-cache-with-time-to-live

Score: 5

Category: basics

Read More

Ttl-Cache-1

Sat 17 May 2025

title: "TTL Cache Check" author: "Rj" date: 2019-04-20 description: "-" type: technical_note draft: false


from cachetools import TTLCache 
import time
cache = TTLCache(maxsize=10, ttl=10)
cache['city'] = 'Toronto'
print(cache['city'])
Toronto
time.sleep(5)
if('city' in cache):
    print(cache['city'])
else:
    print('Cache not found')
Toronto
time.sleep …

Category: basics

Read More

Unicode-Dammit

Sat 17 May 2025

title: "Unicode Dammit" author: "Rj" date: 2019-04-20 description: "-" type: technical_note draft: false


from bs4 import UnicodeDammit
print("inside main method")

dammit = UnicodeDammit(b"Sacr\xc3\xa9 bleu!")
inside main method
print(type(dammit))
<class 'bs4.dammit.UnicodeDammit'>
print(dammit.unicode_markup)
Sacré bleu!
print(type(dammit.unicode_markup))
<class 'str'>
print(dammit …

Category: basics

Read More

User-Input

Sat 17 May 2025

title: "User input" author: "Rj" date: 2019-04-20 description: "-" type: technical_note draft: false


city = input("Enter your city : ")
Enter your city : Toronto
city
'Toronto'


Score: 0

Category: basics

Read More

Various-Algorithms

Sat 17 May 2025

title: "Various Algorithms" author: "Rj" date: 2019-04-20 description: "-" type: technical_note draft: false


Source:

https://www.kaggle.com/drfrank/estonia-disaster-visualization-machine-learning

import numpy as np
from sklearn.linear_model import LinearRegression
from sklearn.model_selection import train_test_split, GridSearchCV, cross_val_score
from sklearn.metrics import confusion_matrix, accuracy_score, classification_report

X = np.array(
    [
        [1, 1], [1, 2], [2 …

Category: basics

Read More

Various-Algorithms-Titanic

Sat 17 May 2025

title: "Various Algorithms Titanic" author: "Rj" date: 2019-04-20 description: "-" type: technical_note draft: false


Source:

https://www.kaggle.com/drfrank/estonia-disaster-visualization-machine-learning

https://stackoverflow.com/questions/55240330/how-to-read-csv-file-from-github-using-pandas

https://gist.github.com/michhar/2dfd2de0d4f8727f873422c5d959fff5

https://www.kaggle.com/rajacsp/titanic-basic-analysis

import pandas as pd

url = 'https://gist.githubusercontent.com/michhar/2dfd2de0d4f8727f873422c5d959fff5/raw …

Category: basics

Read More

Versions

Sat 17 May 2025

title: "Versions" author: "Rj" date: 2019-04-20 description: "List Test" type: technical_note draft: false


# scipy
import scipy
print('scipy: %s' % scipy.__version__)
scipy: 1.2.1
# numpy
import numpy
print('numpy: %s' % numpy.__version__)
numpy: 1.16.2
# matplotlib
import matplotlib
print('matplotlib: %s' % matplotlib.__version__)
matplotlib: 3.0.3
# pandas …

Category: basics

Read More

Webanalyzer Simple

Sat 17 May 2025

title: "Web Analyzer Simple" author: "Rj" date: 2019-04-20 description: "-" type: technical_note draft: false


import webanalyzer
w = webanalyzer.WebAnalyzer()

w.headers = {
    "User-Agent": "custom ua",
    "header-key": "header-value"
}

w.allow_redirect = True
w.aggression = 0
r = w.start("http://www.fatezero.org")

print(r)
[{'name': 'Script', 'origin': 'whatweb'}, {'name': 'HTML5', 'origin': 'whatweb'}, {'name': 'Fastly …

Category: basics

Read More
Page 16 of 17

« Prev Next »