You're browsing snippets anonymously. Log in or create an account to save and manage your own snippets.

Public Snippets
using language: Python
Showing 5 snippets
Reset default python log handlers
import logging

formatter = logging.Formatter('FOO: %(message)s')

root_logger = logging.getLogger()
root_logger.setLevel(logging.INFO)

# This is the key line that removes the double logging
...
By xtream1101 Updated 2025-03-04 18:33
Django graphene mutation input validation
import graphene

class ScratchpadMutation(graphene.relay.ClientIDMutation):
    class Input:
        created_by = graphene.String(required=True)
        foobar = graphene.String()

    test = g...
By xtream1101 Updated 2025-02-06 14:13
Try, try again - Multiple try/except blocks in a flat format
data = {'some_key': 'key value'}
key_data = None
for _ in range(1):
    try:
        key_data = data['someKey']
    except Exception: pass
    else: break  # It worked

    try:
        key_d...
By xtream1101 Updated 2025-02-06 13:43
Multi key sort on a list of dicts
data = [
    {'name': 'Alice', 'age': 25, 'city': 'New York'},
    {'name': 'Bob', 'age': 30, 'city': 'London'},
    {'name': 'Charlie', 'age': 20, 'city': 'New York'}
]

# Sort by 'city' first,...
By xtream1101 Updated 2025-02-06 13:27
Python command test
import sys

if __name__ == "__main__":
	print(f"args passed in: {sys.argv[1:]}")
By xtream1101 Updated 2025-02-06 05:12
Showing 5 snippets