Skip to content

Instantly share code, notes, and snippets.

View richard-mihalovic's full-sized avatar

Richard Mihalovič richard-mihalovic

View GitHub Profile
import socket
def has_mongodb(host, port=27017):
try:
host_addr = socket.gethostbyname(host)
if not host_addr:
return False
@richard-mihalovic
richard-mihalovic / dict_read_value.py
Last active August 29, 2015 14:13
Read value in Python dict and checks if keys exists.
def dict_read_value(src, path, default=None):
value = src
keys = path.split('.')
for key in keys:
if isinstance(value, dict) and key in value:
value = value[key]
else:
return default